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: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: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//1500K 1172MS
#include<stdio.h>
#include<string.h>
#include<math.h>
#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("%dn",n-count/2);}return 0;
}
本文发布于:2024-01-31 11:56:30,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170667339328351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |