1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| #include<bits/stdc++.h> using namespace std; #define N 107 int zero[N],vis[N],a[N]; int d[N][N]; int like[N],mlike[N]; map<int,int> mp; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int m,k,chang,i,j,maxilike,ka,maximlike; char ss[17]; while(scanf("%d%d",&m,&k)!=EOF) { mp.clear(); for(i=0;i<k;i++) { scanf("%d",&a[i]); mp[a[i]] = 1; } memset(zero,0,sizeof(zero)); maxilike = maximlike = -10000; scanf("%d",&chang); for(i=0;i<chang;i++) { scanf("%s",ss); scanf("%d",&ka); for(j=0;j<ka;j++) { scanf("%d",&d[i][j]); if(d[i][j] == 0) zero[i]++; } if(ka == m) { maxilike = max(maxilike,k); maximlike = max(maximlike,k); mlike[i] = k; like[i] = k; } else { int ca = 0; memset(vis,0,sizeof(vis)); for(j=0;j<k;j++) vis[a[j]] = 1; for(j=0;j<ka;j++) { if(mp[d[i][j]]) ca++; vis[d[i][j]] = 1; } int unvis = 0; for(j=1;j<=m;j++) { if(!vis[j]) unvis++; } if(unvis < zero[i]) { like[i] = ca + zero[i] - unvis; mlike[i] = ca + min(zero[i],k-ca); } else { mlike[i] = ca + min(zero[i],k-ca); like[i] = ca; } maxilike = max(maxilike,like[i]); maximlike = max(maximlike,mlike[i]); } } for(i=0;i<chang;i++) { if(like[i] >= maximlike || (like[i] >= maxilike && mlike[i] == maximlike)) { if(like[i] >= maximlike) printf("0\n"); else { int flag = 1; for(j=0;j<chang;j++) { if(j!=i && like[i] < mlike[j]) { flag = 0; break; } } if(flag) printf("0\n"); else printf("2\n"); } } else if(mlike[i] < maxilike) printf("1\n"); else printf("2\n"); } } return 0; }
|