Codeforces Round #647 (Div. 2) A~D题解

目录

A. Johnny and Ancient Computer

B. Johnny and His Hobbies

C. Johnny and Another Rating Drop

D. Johnny and Contribution


A. Johnny and Ancient Computer

题意:给定两个数A,B,问A能不能不断通过乘或除2、4、8(能整除才能除),得到B

思路:如果A能得到B,B也能得到A,所以AB的大小关系假定为A大B小。如果A不能整除B,则不可能得到B,否则计算出AB倍数,为了让步数最小先除8再除4再除2,如果最后剩的数非1,则也不能得到B。

AC代码:

/*---------------------------------
 *File name: A.cpp
 *Creation date: 2020-06-05 09:18
 *Link:https://codeforces.com/contest/1362/problem/A 
 *-------------------------------*/
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define LL long long
#define PII pair<int, int>
#define Pque priority_queue 
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double EPS = 1e-8;

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		LL a , b;
		scanf("%lld %lld", &a, &b);
		LL ans = 0;
		if(a < b) swap(a, b);
		if(a % b != 0) printf("-1\n");
		else {
			LL times = a / b;
			while(times % 8 == 0) times /= 8, ans++;
			while(times % 4 == 0) times /= 4, ans++;
			while(times % 2 == 0) times /= 2, ans++;
			if(times != 1) printf("-1\n");
			else printf("%lld\n", ans);
		}
	}
	return 0;
}

B. Johnny and His Hobbies

题意:给定n个各不相同的数集,问能不能选择一个K,使得每个数异或K之后的数集与原数集

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值