您的位置:首页 > 其它

Codeforces Round #469 (Div. 1) B. A Leapfrog in the Array(dfs)

2018-03-10 14:46 351 查看
题目链接:http://codeforces.com/contest/949/problem/B

理性分析之后,发现直接dfs就可以了

代码:#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll dfs(ll now)
{
if(now&1==1)
return (now+1)/2;
return dfs(now+n-(now/2+1)+1);
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int q;
scanf("%lld%d",&n,&q);
while(q--)
{
ll x;
scanf("%lld",&x);
printf("%lld\n",dfs(x));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: