POJ 2771 Guardian of Decency
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
对于都不满足条件的连边
这道问题就转换成了从中选取一些点使其两两不相邻
最大点独立集的裸题
最大点独立集=N-二分图最大匹配
这毒瘤题居然卡Dinic!!!
这种出题人就应该被挂起来淦!!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=1001;
int vis[MAXN];
int link[MAXN];
int map[MAXN][MAXN];
int N;
bool dfs(int x)
{
for(int i=1;i<=N;i++)
{
if(map[x][i]&&!vis[i])
{
vis[i]=1;
if(!link[i]||dfs(link[i]))
{
link[i]=x;
return 1;
}
}
}
return 0;
}
struct S
{
int tall;
string a,b,c;
}s[MAXN];
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int Test;
scanf("%d",&Test);
while(Test--)
{
memset(vis,0,sizeof(vis));
memset(link,0,sizeof(link));
memset(map,0,sizeof(map));
scanf("%d",&N);
for(int i=1;i<=N;i++)
cin>>s[i].tall>>s[i].a>>s[i].b>>s[i].c;
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
if(i!=j&&s[i].a!=s[j].a&&s[i].b==s[j].b&&s[i].c!=s[j].c&&fabs(s[i].tall-s[j].tall)<=40 )
map[i][j]=1;
int ans=0;
for(int i=1;i<=N;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%dn",(N*2-ans)/2 );
}
return 0;
}
- Kafka实战:从RDBMS到Hadoop,七步实现实时传输
- Apache NiFi 1.0.0测试版:邮件路由应用新型ListenSMTP
- 为什么我坚持使用 JavaScript 函数声明
- NewSQL数据库大对象块存储原理与应用
- 使用xUnit为.net core程序进行单元测试(下2)
- MongoDB + Spark: 完整的大数据解决方案
- 如何实现自然语言处理的集束搜索解码器
- PostgreSQL 使用advisory lock或skip locked消除行锁冲突, 提高几十倍并发更新效率
- 流动的数据——使用 RxJS 构造复杂单页应用的数据逻辑
- 内存泄漏的检测、解决、防止
- 大数据Hadoop快速入门教程
- 用Rust解决C语言的隐患
- GAN学习指南:从原理入门到制作生成Demo
- 从糖尿病监测看智能医疗发展
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Uber为什么放弃Postgres选择迁移到MySQL?
- BAT 批处理命令 - 文件批量复制、克隆功能实例演示
- 【35期】谈谈你对Java线程之间通信方式的理解
- mac 技术篇-修改hosts文件,hosts文件位置
- 一行能装逼的 JavaScript 代码
- python 技术篇-时间戳的获取,记录程序处理时间
- 基于SpringBoot AOP面向切面编程实现Redis分布式锁
- Python+Selenium 技巧篇-svg标签内元素的xpath定位方式
- 小书MybatisPlus第5篇-Active Record模式精讲
- Python 语法问题-module ‘pip._internal‘ has no attribute ‘pep425tags‘. 原因及解决办法,32位、64位查看pip支持万能方法
- 总在说 Spring Boot 内置了 Tomcat 启动,那它的原理你说的清楚吗?
- JavaScript 技巧篇-js增加延迟时间解决单击双击事件冲突,双击事件触发单击事件
- Python 技术篇-sha256()加密的使用方法,sha1、md5加密方法
- Python 技术篇-如何打印一段文字,用友云霸气控制台颜文字打印
- Python 技术篇-获取秒级时间戳、毫秒级时间戳