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;
}
理性分析之后,发现直接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;
}
相关文章推荐
- Codeforces Round #469 (Div. 2)D. A Leapfrog in the Array(递推)
- Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维)
- Codeforces Round #469 (Div. 2) D A Leapfrog in the Array
- Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维)
- Codeforces Round #469 (Div. 2) D - A Leapfrog in the Array 推规律+递归
- Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array(找规律)
- codeforces 949B :A Leapfrog in the Array
- codeforces- 949B - A Leapfrog in the Array(思维)
- Codeforces 950D A Leapfrog in the Array
- codeforces 949B A Leapfrog in the Array
- cf 949B A Leapfrog in the Array
- Codeforces 949B A Leapfrog in the Array(数学,规律)
- Codeforces--949B--A Leapfrog in the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
- Codeforces Round #251 (Div. 2) C Devu and Partitioning of the Array
- Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力
- Codeforces Round #251(Div. 2) 439C. Devu and Partitioning of the Array 构造
- Find the Smallest K Elements in an Array
- Data Structure Array: Find the two numbers with odd occurrences in an unsorted array
- Codeforces Round #358 (Div. 2) C. Alyona and the Tree (二叉树+DFS)