码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!

时间:2020-06-05 12:59:47      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:created   txt   gif   图片   codeforce   def   test   open   简单   

题目链接:http://codeforces.com/contest/1362

 

简单讲解:https://www.bilibili.com/video/BV15C4y1a7e5

A - Johnny and Ancient Computer

技术图片
//
//  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\n");continue;
    }
    else if((a%2!=0)&&(b%2!=0))
    {
        printf("-1\n");continue;
    }
    if(a>b)
    {
        if(a%b!=0)
           printf("-1\n");
        else
           {
               long long ma=a/b;
               if((ma&(ma-1))!=0)
                   printf("-1\n");
               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\n",num);
               }
           }
    }
    else{
        if(b%a!=0)
           printf("-1\n");
        else
        {
            long long maa=b/a;
           if((maa&(maa-1))!=0)
               printf("-1\n");
            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\n",num);
                }
           }
    }
    }
    return 0;
}
View Code

 

B - Johnny and His Hobbies

技术图片
//-------------------------------------------------
//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\n",num);
            else
                printf("-1\n");
        }
     return 0;
}
View Code

 

C - Johnny and Another Rating Drop

技术图片
#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\n",ee(n));
    }
    return 0;
}
View Code

 

Codeforces Round #647 (Div. 2) - Thanks, Algo Muse!

标签:created   txt   gif   图片   codeforce   def   test   open   简单   

原文地址:https://www.cnblogs.com/Vampire6/p/13049059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!