D. A Leapfrog in the Array Codeforces Round #469 (Div. 2)

题目链接:http://codeforces.com/contest/950/problem/D
参考链接:https://blog.csdn.net/xiangAccepted/article/details/79506332
所得:我原本是找单个样例的规律,但是找出来后发现还是会超时,看了上面的参考链接后发现,原来最省事的规律是在一系列样例之间找规律

#include <bits/stdc++.h>
#define pi acos(-1)
#define fastcin ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL ll_INF = 0x3f3f3f3f3f3f3f3f;//4e18 ~= 2^62
const int maxn =10000 + 10;
const LL mod = 1e9+7;




int main()
{
    LL n, p, loc;
    scanf("%I64d%I64d", &n, &p);
    while(p--){
        scanf("%I64d", &loc);
        if(loc&1) printf("%I64d\n", (loc+1)/2);
        else{
            LL ceng = n;
            while(!(loc&1)){
                loc = ceng - loc/2;
                ceng = loc;
            }
            printf("%I64d\n", n-ceng+(loc+1)/2);
        }
    }
}
阅读更多

没有更多推荐了,返回首页