Codeforces #554 A B C

 A.取两边奇数偶数最小求和就行

//Codeforces Round 554A
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6+6;
int main()
{
	int oa=0,ob=0,ea=0,eb=0;
	int n,m,tp;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&tp);
		if(tp%2==0)ea++;
		else oa++;
	}
	for(int i=0;i<m;i++){
		scanf("%d",&tp);
		if(tp%2==0)eb++;
		else ob++;
	}
	int ans = min(ea,ob)+min(eb,oa);
	printf("%d",ans);
	return 0;
}

 B.模拟一下第一个样例,然后按照它的方法写就行

//Codeforces Round 554B
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6+6;
int quick(int x,int y){
	int as = 1;
	while(y){
		if((y&1))as*=x;
		x*=x;
		y>>=1;
	}
	return as;
}
int find(int num){//找最高位的0 
	int as = -1,tt=1;
	while(num){
		if((!(num&1))) as=tt;	
		num>>=1;	tt++;
	}
	return as;
}
queue<int> ans;
int main()
{
	int num,tp,as=0;
	while(!ans.empty())ans.pop();
	scanf("%d",&num);
	 while(num){
	 	tp = find(num);
	 	if(tp==-1)break;
	 	ans.push(tp);
	 	tp = quick(2,tp) - 1;
	 	num^=tp;
	 	as++;
	 	if(find(num)==-1)break;
		num++;	as++;
	 }
	 cout<<as<<endl;
	 tp = 0;
	 if(!ans.empty())tp = ans.front(),ans.pop(),printf("%d",tp);

	 while(!ans.empty()){
	 	tp = ans.front(); ans.pop();
	 	printf(" %d",tp);
	 }
	 printf("\n");
	return 0;
}

 C. 

 

 

//Codeforces Round 554C
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6+6;
ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);	
}
ll tmp,ans,x,y;
void judge(ll k){
	ll tp = (x+k)*(y+k)/gcd(x+k,y+k);
	if(tp<=tmp){
		if(tp==tmp&&ans>k)ans=k;
		else if(tp==tmp)return ;
		ans = k;
		tmp = tp;
	}
}
int main()
{
	cin>>x>>y;
	tmp = x*y;
	judge(0);
	ll cha = abs(x-y),t1,t2;
	for(int i=1;i*i<=cha;i++){
		if(cha%i==0){
			t1 = i - x%i;
			judge(t1);
			t2 = cha/i; 
			t2 = t2 - y%t2;
			judge(t2);
		}	
	}
	cout<<ans<<endl;
	
	return 0;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wym_king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值