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;
}