题目链接:http://codeforces.com/contest/1362
简单讲解:https://www.bilibili.com/video/BV15C4y1a7e5
A - Johnny and Ancient Computer
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// // main.cpp // CF // // Created by HanJinyu on 2020/5/15. // Copyright © 2020 by HanJinyu. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=2e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--){ long long a,b; scanf("%lld%lld",&a,&b); if(a==b) { printf("0 ");continue; } else if((a%2!=0)&&(b%2!=0)) { printf("-1 ");continue; } if(a>b) { if(a%b!=0) printf("-1 "); else { long long ma=a/b; if((ma&(ma-1))!=0) printf("-1 "); else{ ll num=0; ll count=0; while(1) { if (ma>>=1) count++; else break; } if(count==1) num=1; else if(count!=1) { num+=count/3; count%=3; if(count!=0) num++; } printf("%lld ",num); } } } else{ if(b%a!=0) printf("-1 "); else { long long maa=b/a; if((maa&(maa-1))!=0) printf("-1 "); else{ ll num=0; ll count=0; while(1) { if (maa>>=1) count++; else break; } if(count==1) num=1; else if(count!=1) { num+=count/3; count%=3; if(count!=0) num++; } printf("%lld ",num); } } } } return 0; }
B - Johnny and His Hobbies
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//------------------------------------------------- //Created by HanJinyu //Created Time :三 5/20 12:29:04 2020 //File Name :question.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; #define maxn 100000 int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { int a[maxn],b[maxn]; int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",a+i); } sort(a,a+n); bool flag=false; int num=0; for(int i=1;i<=1024;i++) { bool flag1=false; for(int j=0;j<n;j++) { b[j]=(a[j]^i); } sort(b,b+n); for(int k=0;k<n;k++) { if(a[k]!=b[k]) { flag1=true; break; } } if(!flag1) { num=i; flag=true; break; } } if(flag) printf("%d ",num); else printf("-1 "); } return 0; }
C - Johnny and Another Rating Drop
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 2e5+10; long long ee(long long a) { if(a==1) return 1; else if(a==2) return 3; return ee(a/2)+a; } int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { ll n; scanf("%lld",&n); printf("%lld ",ee(n)); } return 0; }
D - Johnny and Contribution
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// // main.cpp // CF // // Created by HanJinyu on 2020/5/15. // Copyright © 2020 by HanJinyu. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=5e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int n,m; scanf("%d%d",&n,&m); vector<int>vv[n+20],where[n+20],ans; int u,v; for(int i=1;i<=m;i++) { scanf("%d%d",&u,&v); vv[u].push_back(v); vv[v].push_back(u);//连边 } int point[maxn];//所求的权值 int x; for(int i=1;i<=n;i++) { scanf("%d",&x); where[x].push_back(i); point[i]=1;//每个编号目标权值都设置成1 } for(int i=1;i<=n;i++) { for(auto v1:where[i])//遍历每个目标权值他所对应点额编号 { if(point[v1]!=i)//所求的权值与题目求是否一致,不一致就-1 { printf("-1 "); return 0; } for(auto s:vv[v1])//更新他周围的权值 { if(point[s]==i)//只要跟当前的编号就要更新 point[s]++; } ans.push_back(v1);//把编号存入答案 } } for(auto v:ans) printf("%d ",v); printf(" "); return 0; }