是一道二分图最大独立集的裸题,,,就是看着麻烦了点,,其实很简单。题目:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 3584 | Accepted: 1493 |
Description
Input
Output
Sample Input
2 4 35 M classicism programming 0 M baroque skiing 43 M baroque chess 30 F baroque soccer 8 27 M romance programming 194 F baroque programming 67 M baroque ping-pong 51 M classicism programming 80 M classicism Paintball 35 M baroque ping-pong 39 F romance ping-pong 110 M romance Paintball
Sample Output
3 7ac代码:
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> #include <string.h> #include <vector> #include <string> using namespace std; vector<int> ss[505]; int flag[505],visted[505]; struct people{ int height; char male; string music; string pe; }aa[505]; bool dfs(int x){ for(int i=0;i<ss[x].size();++i){ if(!visted[ss[x][i]]){ visted[ss[x][i]]=1; if(flag[ss[x][i]]==-1||dfs(flag[ss[x][i]])){ flag[ss[x][i]]=x; return true; } } } return false; } int main(){ int t; scanf("%d",&t); while(t--){ int n; memset(flag,-1,sizeof(flag)); memset(ss,0,sizeof(ss)); scanf("%d",&n); for(int i=0;i<n;++i){ cin>>aa[i].height>>aa[i].male>>aa[i].music>>aa[i].pe; } for(int i=0;i<n;++i){ for(int j=0;j<n;++j){ int x=abs(aa[j].height-aa[i].height); if(x<=40&&aa[j].male!=aa[i].male&&aa[j].music==aa[i].music&&aa[j].pe!=aa[i].pe){ ss[i].push_back(j); } } } int sum=0; for(int i=0;i<n;++i){ memset(visted,0,sizeof(visted)); if(dfs(i)) sum++; } printf("%d\n",n-sum/2); } return 0; }