这多捞啊,我回不了学校了
不能回学校参加校训,我真的裂开。
A - Johnny and Ancient Computer
题目链接:https://codeforces.ml/contest/1362/problem/A
是该反省为什么水题切那么慢了QAQ。
#include <iostream>
#define LL long long
using namespace std;
LL a,b;
int ans;
int t;
int main(){
scanf("%d",&t);
while(t--){
scanf("%lld %lld",&a,&b);
LL m=max(a,b);
LL n=min(a,b);
bool flag=1;
ans=0;
while(n<m){
n*=2;
ans++;
}
if(n==m) cout<<ans/3+min(1,ans%3)<<endl;
else cout<<"-1"<<endl;
}
}
B. Johnny and His Hobbies
题目链接:https://codeforces.ml/contest/1362/problem/B
这题直接暴力求解,当时写的时候不知道vector容器可以直接比较是否相等。。。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T,n;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
vector <int> s;
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
s.push_back(x);
}
sort(s.begin(),s.end());
int ans=-1;
for(int k=1;k<=1024;k++){
vector <int> v;
for(int i=0;i<n;i++){
v.push_back(s[i]^k);
}
sort(v.begin(),v.end());
if(s==v){
ans=k;
break;
}
}
cout<<ans<<endl;
}
}
C. Johnny and Another Rating Drop
题目链接:https://codeforces.ml/contest/1362/problem/C
c题我是真没想到这样写,先随便连列举一下
0000
0001
0010
0011
0100
0101
然后发现二进制从右数第一位变换贡献为n
第二位贡献为n/2
第三位为n/4
以此类推
#include <iostream>
#define LL long long
using namespace std;
int t;
LL n;
int main(){
scanf("%d",&t);
while(t--){
scanf("%lld",&n);
LL ans=n;
while(n>0){
n/=2;
ans+=n;
}
cout<<ans<<endl;
}
}

浙公网安备 33010602011771号