hdu6655 Just Repeat(贪心)
题目链接
大意:两个人玩游戏,每回合一方可以放另一方没有放过的卡,谁最后没卡放谁输
思路:每回合,出卡的人肯定要出场上最多的卡,这样可以使自己尽量多或者别人尽量少
细节见代码:
#include<bits/stdc++.h>
#define LL unsigned long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
LL k1, k2;
LL rng() {
LL k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
LL t,n,m,a[N],b[N],p,cntL[N],cntR[N],A[N],B[N];
LL visL[N],visR[N];
struct uzi{
LL a,L,R;
bool operator <(const uzi &t)const{
return a>t.a;
}
}P[N<<2];
int main(){
ios::sync_with_stdio(false);
for(cin>>t;t;t--){
cin>>n>>m>>p;
for(int i=1;i<=n+m;i++)cntL[i]=visL[i]=0;
for(int i=1;i<=m+n;i++)cntR[i]=visR[i]=0;
if(p==1){
for(int i=1;i<=n;i++)cin>>a[i];
for(int j=1;j<=m;j++)cin>>b[j];
}else{
LL mod;
cin>>k1>>k2>>mod;
for (int i = 1; i <= n; ++i)a[i] = rng() % mod;
cin>>k1>>k2>>mod;
for (int i = 1; i <= m; ++i)b[i] = rng() % mod;
}
for(int i=1;i<=n;i++)A[i]=a[i];
for(int j=1;j<=m;j++)A[j+n]=b[j];
sort(A+1,A+1+n+m);
int L=unique(A+1,A+1+n+m)-A-1;
for(int i=1;i<=n;i++)a[i]=lower_bound(A+1,A+1+L,a[i])-A,cntL[a[i]]++;
for(int i=1;i<=m;i++)b[i]=lower_bound(A+1,A+1+L,b[i])-A,cntR[b[i]]++;
for(int i=1;i<=L;i++){
P[i].a=cntL[i]+cntR[i];
P[i].L=cntL[i];
P[i].R=cntR[i];
}
sort(P+1,P+1+L);
int sta=0;
LL Ls=0,R=0;
for(int i=1;i<=L;i++){
if(!P[i].L)R+=P[i].R;
else if(!P[i].R)Ls+=P[i].L;
else{
if(!sta){
Ls+=P[i].L;
}else R+=P[i].R;
sta^=1;
}
}
if(Ls>R)cout<<"Cuber QQ\n";
else cout<<"Quber CC\n";
}
return 0;
}