Datahub
数据改变生活

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.

样例输入 Copy

2

10

20

样例输出 Copy

6

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;

}


文章分类: 算法例题
分享到:
QQ:258506508                                     联系电话:020-000000    000-000000                                   联系邮箱:xxx@.co.m                                     联系地址:XXX省XXX市XXX县XXX路