zoukankan      html  css  js  c++  java
  • 这多捞啊,我回不了学校了

    不能回学校参加校训,我真的裂开。

     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;
        	}
        }
    
  • 相关阅读:
    2019暑假集训 windy数
    2019暑假集训 数字游戏
    2019暑假集训 周年纪念晚会
    2019暑假集训 加分二叉树
    0013-求圆柱体体积
    0012-求滑动距离
    0011-绝对值函数
    0010-温度转换
    0009-乘法问题
    0008-三位数倒序问题
  • 原文地址:https://www.cnblogs.com/kksk/p/13057787.html
Copyright © 2011-2022 走看看