1154: Boring XiaoMing发表时间:2022-10-27 19:15 1154: Boring XiaoMing时间限制: 1 Sec 内存限制: 128 MB 题目描述As the most famous man in the word, XiaoMing found that plople "orz(膜拜)" him everyday,so he always felt bored and play game everytime. Now XiaoMing comes up with a boring game.The rules of the game will be told below: There are N+2 grids in a line.Initially,XiaoMing stands on the zeroth grid.Firstly,he jumps out N steps.Then he stands on the Nth grid.After that,he turns around and jumps out a=⌊N/2⌋ steps.Then he turns around again and jumps out b=⌊a/2⌋ steps.He does the steps again and again until he can just jumps out 0 step. Can you tell XiaoMing which gird he will stand on at the end of the game. 输入The first line is a integer T indicating T cases.Then T lines fllow,each line is a positive integer N. 1<=T<=1000 1<=N<=100000 输出The answer. 样例输入 Copy2 10 20 样例输出 Copy6 14 提示For the first case: Begin: 0->10 10->5 5->7 7->6 End #include<bits/stdc++.h> using namespace std; int main(){ int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); int now=0,f=1; while(n){ now+=f*n; f=-f;n/=2; } printf("%d\n",now); } return 0; }
文章分类:
算法例题
|