题目连接 : https://codeforces.com/contest/1151/problem/B
可能我想法有问题,我怎么感觉B题的思路不直接想出来的,我想了一会才想出来,感觉不难,但可能有更简单的算法没想到。
AC代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> #include<iostream> #include<math.h> #include<vector> #include<queue> using namespace std; //int a[510][510]; int vis[1024]; typedef struct W_W{ int eend; int weight; }miao; miao x[510][510]; int flag[510]; int main() { int m,n; scanf("%d %d",&n,&m); //memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++){ memset(vis,0,sizeof(vis)); int ge=0; for(int j=0;j<m;j++){ int a; scanf("%d",&a); if(vis[a]==0){ vis[a]=1; x[i][ge].eend=j; x[i][ge].weight=a; ge++; } } flag[i]=ge; } int sum=0; for(int i=0;i<n;i++){ sum^=x[i][0].weight; } if(sum!=0){ printf("TAK "); for(int i=0;i<n;i++){ printf("%d ",x[i][0].eend+1); } printf(" "); } else{ int tt=-1; for(int i=0;i<n;i++){ if(flag[i]>1){ tt=i; break; } } if(tt==-1) printf("NIE "); else{ printf("TAK "); for(int i=0;i<n;i++){ if(i!=tt){ printf("%d ",x[i][0].eend+1); } else{ printf("%d ",x[i][1].eend+1); } } printf(" "); } } return 0; }