首页 > 其他 > 详细

M - Sekiro

时间:2020-03-18 17:57:21      阅读:74      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

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.

代码  ps:除以2,向上取整,k的取值为0或1时退出循环,否则超时

#include<iostream>
using namespace std;
int main(){
    int t;
    int n,k;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d",&n,&k);
        while(k--){
            if(n%2==0) n=n/2;
            else n=n/2+1;
            if(n==1||n==0) break;
        }
        printf("%d\n",n);
    }
}

 

 

M - Sekiro

原文:https://www.cnblogs.com/-happy-/p/12518106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!