标签:cti tca line put throw and div ever include
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2279 Accepted Submission(s): 886
以cat_lover和dog_lover把观众分为两个集合。只要两个集合内的人的选择有冲突,这两个顶点连接,边代表矛盾,然后求最大独立集。
最大独立集 = 顶点数 - 最小顶点覆盖数(最大匹配数)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define N 510 using namespace std; char ch1,ch2; bool vis[N]; int t,x,y,n,m,k,ans,sdog,scat,girl[N],map[N][N]; struct Cat { int like,hate; }cat[N]; struct Dog { int like,hate; }dog[N]; int find(int x) { for(int i=1;i<=sdog;i++) { if(!vis[i]&&map[x][i]) { vis[i]=true; if(girl[i]==-1||find(girl[i])) {girl[i]=x; return 1;} } } return 0; } int main() { scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); ans=0;sdog=0,scat=0; memset(map,0,sizeof(map)); for(int i=1;i<=k;i++) { getchar();//读入换行 scanf("%c%d",&ch1,&x); getchar();//读入空格 scanf("%c%d",&ch2,&y); if(ch1==‘C‘) { cat[++scat].like=x; cat[scat].hate=y; } else { dog[++sdog].like=x; dog[sdog].hate=y; } } for(int i=1;i<=scat;i++) for(int j=1;j<=sdog;j++) if(cat[i].like==dog[j].hate||cat[i].hate==dog[j].like) map[i][j]=1; memset(girl,-1,sizeof(girl)); for(int i=1;i<=scat;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",k-ans); } return 0; }
标签:cti tca line put throw and div ever include
原文地址:http://www.cnblogs.com/z360/p/7435258.html