Race [simulation]

Subject description:

Here Insert Picture Description

Ideas:

Process problems, there are two cases. First, the speed limit had not been accelerated to reach the finish line. Second, to speed up, slow down to the speed limit. So Points can be simulated.

#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
typedef unsigned long long ll;
const ll mod=1e9+10;
 
int main()
{
    int K,N;
    cin>>K>>N;
    while(N--)
    {
        int X;
        cin>>X;
        int add=0,reduce=0;
        int sp=1,ti=0;
        while(1)
        {
            add+=sp;
            ti++;
            if(add+reduce>=K)
            {
                cout<<ti<<endl;
                break;
            }
            if(sp>=X)
            {
                reduce+=sp;
                ti++;
                if(add+reduce>=K)
                {
                    cout<<ti<<endl;
                    break;
                }
            }
            sp++;
        }
    }
    return 0;
}
Published 40 original articles · won praise 0 · Views 910

Guess you like

Origin blog.csdn.net/weixin_45619734/article/details/104782800