作者:青春快乐1 | 来源:互联网 | 2023-10-15 19:23
点击打开链接
Guardian of Decency
Time Limit: 3000MS |
|
Memory Limit: 65536K |
Total Submissions: 4675 |
|
Accepted: 1957 |
Description
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.
Input
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.
Output
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.
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
Northwestern Europe 2005
老师带学生旅游,但是不能带贪恋的学生,问老师最多带多少人。不谈恋爱标准:
1:身高差距大于40(个人认为真心相爱的话身高只是一个符号)
2:性别是一样的
3:音乐喜好不一样
4:运动爱好是一样的
除了第二条,搞不懂这个老师是怎么认为两个人贪恋爱的。。O__O"…
将发生贪恋爱的人配对,则答案为此二分图的最大独立集,因为x,y的集合都是从1~n,左右对称,所以求出最大匹配值之后,还要除以2.
最大独立集=总点个数-最大匹配数。
//1500K 1172MS
#include
#include
#include
#define M 507
int link[M],g[M][M];
bool vis[M];
int n;
struct ST
{
int height;
char sex[2],music[107],sport[107];
}pupils[M];
bool judge(int x,int y)
{
if(fabs(pupils[x].height-pupils[y].height)>40||strcmp(pupils[x].sex,pupils[y].sex)==0||strcmp(pupils[x].music,pupils[y].music)!=0||strcmp(pupils[x].sport,pupils[y].sport)==0)
return false;
return true;
}
bool find(int i)
{
for(int j=1;j<=n;j++)
if(!vis[j]&&g[i][j])
{
vis[j]=true;
if(!link[j]||find(link[j]))
{
link[j]=i;
return true;
}
}
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(link,0,sizeof(link));
memset(g,0,sizeof(g));
int count=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%s%s%s",&pupils[i].height,pupils[i].sex,pupils[i].music,pupils[i].sport);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(judge(i,j))g[i][j]=1;
for(int i=1;i<=n;i++)
{
memset(vis,false,sizeof(vis));
if(find(i))count++;
}
printf("%d\n",n-count/2);
}
return 0;
}