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

题目链接:http://codeforces.com/contest/949/problem/B


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


代码:

#include
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;
}

你可能感兴趣的:(codeforces)