首页 > 其他 > 详细

【CodeForces - 950D】A Leapfrog in the Array

时间:2018-03-10 11:31:39      阅读:240      评论:0      收藏:0      [点我收藏+]

Description

题目地址: Codeforces

Solution

对于一个询问q,如果q是奇数,那么答案就是(q-1)/2

否则将不断q=q/2+n即可

Code

#include <cstdio>
long long n,x;
int q;
int main(){
    scanf("%I64d%I64d",&n,&q);
    while(q--){
        scanf("%I64d",&x); 
        while(!(x&1)) x=(x>>1)+n;
        printf("%I64d\n",(x+1)>>1);
    }
    return 0;
}

【CodeForces - 950D】A Leapfrog in the Array

原文:https://www.cnblogs.com/void-f/p/8537336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!