Sample Input
4
10 1
7 1
10 2
7 2
Sample Output
5
4
3
2
Hint
For the third sample test case, when BaoBao dies for the first time, the money he carries will be reduced from 10 to 5; When he dies for the second time, the money he carries will be reduced from 5 to 3.
水题
题意:给你一个数n 和循环的次数 k,每次循环n都除以2,如果这个数不能整除则向上取整,否则直接除以2。问你循环完最后的数。
思路:
1.注意当n等于0,直接输出0。
2.再循环中如果n等于1,break掉,直接输出1,因为再往下怎么循环都是1,浪费时间了。
AC代码:
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
if(n==0)
cout<<"0"<<endl;
else
{
ll flag=0;
for(int i=1;i<=m;i++)
{
if(n/2!=(double)n/2)
{
n=n/2+1;
if(n==1)
{
flag=1;
break;
}
}
else
{
n=n/2;
}
}
if(flag==1)
cout<<"1"<<endl;
else
cout<<n<<endl;
}
}
return 0;
}