cf950d A Leapfrog in the Array

考虑在位置 (p) 的青蛙。
如果 (p) 是奇数,答案显然是 ((p+1)/2)
否则,由于未跳时 (p) 左边有 (p/2) 只,则 (p) 右边有 (n-p/2) 只,则这青蛙是从 (p+n-p/2) 处跳过来的。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int q;
ll n, uu;
ll f(ll x){
	if(x&1)	return (x+1)/2;
	else	return f(n+x/2);
}
int main(){
	cin>>n>>q;
	while(q--){
		scanf("%I64d", &uu);
		printf("%I64d
", f(uu));
	}
	return 0;
}
原文地址:https://www.cnblogs.com/poorpool/p/8545948.html