标签:eof text require ems tab cte 有一个 space blank
Time Limit: 3000MS | Memory Limit: 65536K | |
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 7
Source
四个条件有一个满足就可以同时带出去,那么四个条件都不满足就不能同时带出去
四个条件都不满足的两个人之间连一条边
然后求最大点独立集
#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<algorithm> #define N 501 using namespace std; int T,n,ans,tot; bool v[N]; int match[N]; int front[N],nxt[N*N],to[N*N]; int number[N]; struct node { string music,sport; char sex; }e[N]; void add(int u,int v) { to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; } bool go(int u) { for(int i=front[u];i;i=nxt[i]) { if(v[to[i]]) continue; v[to[i]]=true; if(!match[to[i]]||go(match[to[i]])) { match[to[i]]=u; return 1; } } return 0; } int main() { scanf("%d",&T); string b,c; char a; while(T--) { tot=ans=0; memset(front,0,sizeof(front)); memset(match,0,sizeof(match)); scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&number[i]); cin>>e[i].sex>>e[i].music>>e[i].sport; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(i==j) continue; if(abs(number[i]-number[j])>40) continue; else if(e[i].sex==e[j].sex) continue; else if(e[i].music!=e[j].music) continue; else if(e[i].sport==e[j].sport) continue; add(i,j); } for(int i=1;i<=n;i++) { memset(v,0,sizeof(v)); if(go(i)) ans++; } printf("%d\n",(n*2-ans)/2); } }
标签:eof text require ems tab cte 有一个 space blank
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7113022.html