题目大意
给定多个 n,要求输出满足某种异或性质的最小的 2k(或按题意构造出的答案)。本题可通过打表/找规律解决,并需要对小值(如 n=1,2)特判。
AC代码
打表题
注意特判一下1 and 2
其他的没什么好多说的
其实下次这种题目建议写一个对拍程序
AC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; ll T,n,a=1e18;
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>T; while (T--) { cin>>n; if(n==1 || n==2) { cout<<1<<endl; continue; } ll ans=1; while(true) { ans*=2; if(ans>=n) { cout<<ans<<endl; break; } } } return 0; }
|
心路历程(WA,TLE,MLE……)
哈哈,没特判2