Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 5517 | Accepted: 2322 |
Description
- 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
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
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 <stdio.h>
#include <string.h>
#include <math.h> bool maps[][];
bool use[];
int match[]; struct Stu {
int h;
char sex[];
char music[];
char sport[];
}mans[],womans[]; int nman,nwoman; bool judge(Stu a,Stu b)
{
if(strcmp(a.music,b.music)) return false;
if(!strcmp(a.sport,b.sport)) return false;
if(fabs((a.h-b.h)*1.0)>) return false;
return true;
} bool DFS(int u)
{
for(int i=;i<nwoman;i++)
{
if(!use[i]&&maps[u][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(maps,false,sizeof(maps));
memset(match,-,sizeof(match));
int num;
nman = ;
nwoman = ;
scanf("%d",&num);
for(int i=;i<num;i++)
{
int height;
char sex[];
char musics[];
char sports[];
scanf("%d%s%s%s",&height,sex,musics,sports);
if(sex[]=='M')
{
mans[nman].h = height;
strcpy(mans[nman].sex,sex);
strcpy(mans[nman].music,musics);
strcpy(mans[nman++].sport,sports);
}
if(sex[]=='F')
{
womans[nwoman].h = height;
strcpy(womans[nwoman].sex,sex);
strcpy(womans[nwoman].music,musics);
strcpy(womans[nwoman++].sport,sports);
}
} for(int i=;i<nman;i++)
{
for(int j=;j<nwoman;j++)
{
if(judge(mans[i],womans[j]))
maps[i][j] = true;
}
} int ans = ;
for(int i=;i<nman;i++)
{
memset(use,false,sizeof(use));
if(DFS(i))
ans++;
}
printf("%d\n",num-ans); }
return ;
}
Poj(2771),最大独立集的更多相关文章
- poj 2771 最大独立集
这道题又无耻的抄袭了别人的代码. 刚开始以为是最大匹配,把条件不相符的人连一起,然后求最大匹配,感觉麻烦,然后看了别人的解题报告,是把相符的人连一起,然后减去,其实就是最大独立集. 最大独立集=|G| ...
- POJ 2771 最大独立集 匈牙利算法
(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include &l ...
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- Guardian of Decency POJ - 2771 【二分匹配,最大独立集】
Problem DescriptionFrank N. Stein is a very conservative high-school teacher. He wants to take some ...
- poj 2771 Guardian of Decency 解题报告
题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 Guardian of Decency
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
随机推荐
- pg_stat_statements
Functions pg_stat_statements_reset() returns void pg_stat_statements_reset discards all statistics g ...
- Java初学--无限循环
利用for循环和while循环分别做到,从键盘读取任意数,输入0自动跳出无限循环,并判断有几个正数几个负数. 1.for循环的无限循环: import java.util.Scanner;//引用Sc ...
- (转)@SuppressWarnings的使用、作用、用法
在java编译过程中会出现很多警告,有很多是安全的,但是每次编译有很多警告影响我们对error的过滤和修改,我们可以在代码中加上 @SuppressWarnings(“XXXX”) 来解决 例如:@S ...
- Fedora20 MATE Destop 环境下安装Sougoupinyin输入法+皮肤
卸载ibus # yum erase ibus* 选择性安装 fcitx # yum install fcitx fcitx-configtool $ ls -a $ vi .bashrc .bas ...
- struts配置通配符*来匹配方法,实现动态调用
01:web.xml中配置,启动struts2 <?xml version="1.0" encoding="UTF-8"?> <web-app ...
- mesos概述
mesos解决的问题 不同的分布式运算框架(spark,hadoop,ES,MPI,Cassandra,etc.)中的不同任务往往需要的资源(内存,CPU,网络IO等)不同,它们运行在同一个集群中,会 ...
- Java内部类小程序(成员内部类,静态内部类,匿名内部类)
/** * 测试java内部类(成员内部类,静态内部类,匿名内部类) * 局部内部类不常用,就不写了. * @package :java05 * @author shaobn * @Describe ...
- EBS R12中重新enable失效用户之后,丢失职责
以下请求跑完不能立即生效,需要等上一段时间! oracle support说这并不是一个bug,是一个问题,呵呵,bug和问题,都是你的错,oracle! 工 作中将某个用户失效之后,有可能又需要重新 ...
- test generation和MBIST
The problem of test generation Random test generation Deterministic algorithm for test generation fo ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...