首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces #554 A B C

Codeforces #554 A B C

作者头像
用户2965768
发布2019-08-01 10:23:12
5490
发布2019-08-01 10:23:12
举报
文章被收录于专栏:wymwym

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;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年07月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档