题解:P14054 [SDCPC 2019] Sekiro
题解:P14054 [SDCPC 2019] Sekiro
题目传送门
更好的阅读体验
题目分析
通过简单的计算,可以发现最后的答案是
考虑暴力,但是暴力的时间复杂度是
这时候,聪明的你发现当
因为
-
当
k\le 50 时,暴力求出答案。 -
当
k>50 时,直接输出1 。 -
注意,当
n=0 时,无论k 是多少,结果都是0 ,这里需要特判。
接下来的代码就很简单了。
代码实现
代码:
//洛谷 P14054 [SDCPC 2019] Sekiro
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL//
#define emdl '\n'
typedef long long ll;
typedef unsigned long long ull;
const int MAXN=1+5;
int n,k;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t;
cin>>t;
while(t--){
cin>>n>>k;
//特判 n=0
if(n==0){
cout<<"0"<<emdl;
continue;
}
//贪心
if(k>50){
cout<<"1"<<emdl;
continue;
}
//暴力求出答案
int x=n;
for(int i=1;i<=k;i++){
x=(x+1)/2;
}
cout<<x<<emdl;
}
return 0;
}
时间复杂度