TOJ 1037 POJ 2771 LA 3415 Guardian of Decency / 二分图
2013-08-15 11:47
441 查看
Guardian of Decency
时间限制(普通/Java):1000MS/10000MS 运行内存限制:65536KByte描述
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude
this possibility, he has made some rules that he thinks indicates a low probability two persons will become a couple:
Their height differs by more than 40 cm.
They are of the same sex.
Their preferred music style is different.
Their favourite sport is the same (they are likely to be fans of different teams and that would result in fighting).
So, for any two persons that he brings on the excursion, they must satisfy at least one of the requirements above. Help him find the maximum number of persons he can take, given their vital information
输入
The first line of the input consists of an integer T ≤ 100 giving the number of test cases. The first line of each test case consists of an integer N ≤ 500 giving the number of pupils. Next there
will be one line for each pupil consisting of four space-separated data items:
an integer h giving the height in cm;
a character 'F' for female or 'M' for male;
a string describing the preferred music style;
a string with the name of the favourite sport.
No string in the input will contain more than 100 characters, nor will any string contain any whitespace.
输出
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.
样例输入
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
样例输出
3 7
就是要防止男女搞对象 所以把可能的对象出去 只要去掉男女中的一个就行 求剩下最多的人数 就是责任书减去最大匹配的对数 还是 模板
#include <stdio.h> #include <math.h> #include <string> #define MAX 510 struct person { int height; char sex[3]; char music[110]; char sport[110]; }; person boy[MAX],girl[MAX]; int map[MAX][MAX],vis[MAX]; int Match[MAX]; int n,m; bool check(int i,int j) { if(fabs(boy[i].height-girl[j].height)>40) return false; if(strcmp(boy[i].music,girl[j].music)!=0) return false; if(strcmp(boy[i].sport,girl[j].sport)==0) return false; return true; } bool dfs(int u) { int i,j; for(i = 0; i < m; i++) { if(map[u][i]&&!vis[i]) { vis[i] = 1; if(Match[i]==-1||dfs(Match[i])) { Match[i] = u; return true; } } } return false; } int match() { memset(Match,-1,sizeof(Match)); int i,ret = 0; for(i = 0; i < n; i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ret++; } return ret; } int main() { person p; int i,j,cas,num; scanf("%d",&cas); while(cas--) { memset(map,0,sizeof(map)); scanf("%d",&num); m = n = 0; for(i = 0;i < num; i++) { scanf("%d %s",&p.height,p.sex); if(p.sex[0]=='F') { girl[m].height = p.height; scanf("%s %s",girl[m].music,girl[m].sport); m++; } else { boy .height = p.height; scanf("%s %s",boy .music,boy .sport); n++; } } for(i = 0;i < n; i++) { for(j = 0; j < m; j++) { if(check(i,j)) { map[i][j] = 1; } } } printf("%d\n",num-match()); } }
相关文章推荐
- LA-3415 & POJ-2771 Guardian of Decency 解题报告
- poj 2771 Guardian of Decency----二分图求 最大覆盖集
- POJ 2771 Guardian of Decency【二分图最大独立集】
- POJ 2771 Guardian of Decency (二分图的最大独立集)
- POJ 2771 Guardian of Decency(二分图最大独立集)
- LA - 3415 - Guardian of Decency(二分图最大独立点集)
- POJ 2771 Guardian of Decency(二分图最大独立集)
- poj 2771 uva12083 Guardian of Decency(二分图最大独立集)
- POJ-2771-Guardian of Decency-求二分图最大独立集(匈牙利算法)
- 【二分图+最大独立集】北大 poj 2771 Guardian of Decency
- POJ 2771 Guardian of Decency(二分图最大独立集)
- POJ 2771 Guardian of Decency (二分图最大点独立集)
- poj 2771 Guardian of Decency
- la 3415, 12083 - Guardian of Decency 最大匹配,独立集,覆盖集
- poj 2771 Guardian of Decency 最大独立集
- LA 3415 - Guardian of Decency【最大独立集】
- UVALive 3415 Guardian of Decency(二分图最大独立集)
- POJ 2771 Guardian of Decency(二分匹配-hungary)
- LA 3415 Guardian of Decency (最大独立集)
- POJ 2771 Guardian of Decency(最大独立点集)