C-出队

感觉就是一道递推找规律题,但x为奇数的时候,答案就是(x+1)/2,而偶数的时候,手算递推一下,再数学归纳法……


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m,x;
    scanf("%lld%lld",&n,&m);
    while(m--)
    {
        scanf("%lld",&x);
        while(x%2==0) x=n+x/2;
        printf("%lld\n",(x+1)/2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41061455/article/details/80287750
C-