Codeforces Round #554 (Div. 2)

A

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL MAXN=1e5+10;
LL a[MAXN];
LL b[MAXN];
int main()
{
	LL n,m;
	LL ao=0,ae=0,bo=0,be=0;
	LL sum=0;
	
	scanf("%lld %lld",&n,&m); 
	for(LL i=0;i<n;i++){
		scanf("%lld",&a[i]);
		if(a[i]%2==0){
			ae++;
		}else{
			ao++;
		}
	}
	for(LL i=0;i<m;i++){
		scanf("%lld",&b[i]);
		if(b[i]%2==0){
			be++;
		}else{
			bo++;
		}
	}
	sum=min(ae,bo)+min(ao,be);
	printf("%lld",sum);
	
	return 0;
}

B

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
LL n[40];
LL l[40];
int lenn(LL xx)
{
	int flag=0;
	int len=0;
	while(xx){
		int d=xx%2;
		if(d){
			if(flag) break;
			len++;
		}else{
			flag=1;
			len++;
		}
		xx=xx/2;
	}
	return len;
}
int main()
{
	LL x;
	LL t=1;
	
	scanf("%lld",&x);
	LL xx=x;
	LL ans=0;
	int fflag=1;
	while(xx){
		int d=xx%2;
		if(d==0){
			fflag=0;
		}
		xx=xx/2;
		ans++;
	}
	if(fflag){
		printf("0");
		return 0; 
	}
	ans=pow(2,ans)-1;
	//cout<<ans<<endl;
	for(int i=0;i<=30;i++){
		n[i]=pow(2,i)-1;
	}
	
	LL llen=0;
	while(t<=40){
		if(t%2==0){
			x++;
		}else{
			llen=lenn(x);
			x=x^(n[llen]);
			l[t]=llen;
		}
		if(x==ans){
			printf("%d\n",t); 
			for(int i=1;i<=t;i++){
				if(i%2==0) continue;
				else{
					printf("%d ",l[i]);
				}
			}
			break;
		}
		t++;
	}
	
	
	
	return 0;
 } 

C

# include <bits/stdc++.h>
using namespace std;

typedef long long LL;
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int main()
{
	LL a,b;
	
	scanf("%lld %lld",&a,&b);
	if(a%b==0||b%a==0){
		printf("0");
	}else{
		LL g=gcd(a,b);
		LL k=0;
		if(a>b){
			LL t=a;
			a=b;
			b=t;
		}
		LL c=(b/g)-(a/g);
		while(c!=1){
			b++;
			a++;
			k++;
			g=gcd(a,b);
			c=(b/g)-(a/g);
		}
		printf("%d",k);
	}
	
	return 0;
}

posted @ 2022-02-27 00:18  fengzlj  阅读(23)  评论(0)    收藏  举报