题意:A和B两个人玩游戏,分别有n和m张牌,A的第i张牌是a[i],B是b[i]
两人轮流出牌,如果一种编号的牌被其中一个人出了另一个人就不能出自己手中这个编号的牌
两人都按最优策略行动,问获胜者
思路:
考场上好像卡常,补题的时候似乎没有
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned int uint; 5 typedef unsigned long long ull; 6 typedef pair<int,int> PII; 7 typedef pair<ll,ll> Pll; 8 typedef vector<int> VI; 9 typedef vector<PII> VII; 10 //typedef pair<ll,ll>P; 11 #define N 200010 12 #define M 200010 13 #define fi first 14 #define se second 15 #define MP make_pair 16 #define pb push_back 17 #define pi acos(-1) 18 #define mem(a,b) memset(a,b,sizeof(a)) 19 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++) 20 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--) 21 #define lowbit(x) x&(-x) 22 #define Rand (rand()*(1<<16)+rand()) 23 #define id(x) ((x)<=B?(x):m-n/(x)+1) 24 #define ls p<<1 25 #define rs p<<1|1 26 27 const int MOD=1e9+7,inv2=(MOD+1)/2; 28 double eps=1e-4; 29 int INF=1e9; 30 int inf=0x7fffffff; 31 int dx[4]={-1,1,0,0}; 32 int dy[4]={0,0,-1,1}; 33 34 struct node 35 { 36 int x,y; 37 }q[N]; 38 39 int a[N],b[N],c[N],s[2],d[N][2]; 40 ull k1,k2; 41 42 int read() 43 { 44 int v=0,f=1; 45 char c=getchar(); 46 while(c<48||57<c) {if(c=='-') f=-1; c=getchar();} 47 while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar(); 48 return v*f; 49 } 50 51 unsigned long long rng() 52 { 53 unsigned long long k3 = k1, k4 = k2; 54 k1 = k4; 55 k3 ^= k3 << 23; 56 k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26); 57 return k2 + k4; 58 } 59 60 bool cmp(node a,node b) 61 { 62 return a.x+a.y>b.x+b.y; 63 } 64 65 void solve() 66 { 67 int n1=read(),n2=read(),p=read(); 68 if(p==1) 69 { 70 rep(i,1,n1) a[i]=read(); 71 rep(i,1,n2) b[i]=read(); 72 } 73 else 74 { 75 int mod; 76 scanf("%llu%llu%d",&k1,&k2,&mod); 77 rep(i,1,n1) a[i]=rng()%mod; 78 scanf("%llu%llu%d",&k1,&k2,&mod); 79 rep(i,1,n2) b[i]=rng()%mod; 80 } 81 int t=0; 82 rep(i,1,n1) c[++t]=a[i]; 83 rep(i,1,n2) c[++t]=b[i]; 84 sort(c+1,c+t+1); 85 t=unique(c+1,c+t+1)-c-1; 86 rep(i,1,n1) 87 { 88 a[i]=lower_bound(c+1,c+t+1,a[i])-c; 89 d[a[i]][0]++; 90 } 91 rep(i,1,n2) 92 { 93 b[i]=lower_bound(c+1,c+t+1,b[i])-c; 94 d[b[i]][1]++; 95 } 96 97 int m=0; 98 s[0]=0,s[1]=0; 99 rep(i,1,t) 100 { 101 if(d[i][0]&&d[i][1]) 102 { 103 m++; 104 q[m].x=d[i][0]; 105 q[m].y=d[i][1]; 106 continue; 107 } 108 if(d[i][0]) s[0]+=d[i][0]; 109 if(d[i][1]) s[1]+=d[i][1]; 110 } 111 sort(q+1,q+m+1,cmp); 112 int v=1; 113 rep(i,1,m) 114 { 115 v^=1; 116 if(v==0) s[v]+=q[i].x; 117 else s[v]+=q[i].y; 118 } 119 if(s[0]>s[1]) printf("Cuber QQ\n"); 120 else printf("Quber CC\n"); 121 rep(i,1,t) 122 rep(j,0,1) d[i][j]=0; 123 } 124 125 126 127 int main() 128 { 129 int cas=read(); 130 while(cas--) solve(); 131 return 0; 132 }