POJ 2771
#include <iostream>
#include <string>
#define MAXN 505 using namespace std; int _m[MAXN][MAXN];
int match[MAXN];
bool ck[MAXN]; struct node
{
int _high;
char M_F;
string _music;
string _habit;
};
int hungary(int a,int b);
node _node[MAXN]; int main()
{
// freopen("acm.acm","r",stdin);
int test;
int i;
int j;
int n;
cin>>test;
while(test --)
{
cin>>n;
for(i = ; i < n; ++ i)
{
cin>>_node[i]._high;
cin>>_node[i].M_F;
cin>>_node[i]._music;
cin>>_node[i]._habit;
}
memset(_m,,sizeof(_m));
for(i = ; i < n; ++ i)
{
for(j = ; j < i; ++ j)
{
if(abs(_node[i]._high-_node[j]._high) <= && _node[i].M_F != _node[j].M_F && _node[i]._music == _node[j]._music && _node[i]._habit != _node[j]._habit)
{
_m[i][j] = ;
_m[j][i] = ;
}
}
}
cout<<n-hungary(n,n)/<<endl;
}
} /////////////////////////////////////////////////////////////////////////
//hungary算法,自己写的模板!
/////////////////////////////////////////////////////////////////////////
bool search(int a,int b,int x)
{
int i;
int t;
for ( i = ; i < b ; i++)
if (_m[x][i] && ! ck[i])
{
ck[i] = true;
t = match[i];
match[i] = x;
if (t == - || search(a,b,t))
return true;
match[i] = t;
}
return false;
} int hungary(int a,int b)
{
memset(match,-,sizeof(match));
int max_match = ;
int i;
for ( i = ; i < a ; i++)
{
memset(ck,false,sizeof(ck));
if (search(a,b,i))
max_match++;
}
return max_match;
}
POJ 2771的更多相关文章
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K To ...
- 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
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
- 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 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- POJ 2771 Guardian of Decency(求最大点独立集)
该题反过来想:将所有可能发生恋爱关系的男女配对,那么可以带出去的人数应该等于这个二分图的最大独立集 先要做一下预处理,把不符合要求的双方先求出来, company[i][j]表示i.j四个标准都不符合 ...
- poj 2771 最大独立集
这道题又无耻的抄袭了别人的代码. 刚开始以为是最大匹配,把条件不相符的人连一起,然后求最大匹配,感觉麻烦,然后看了别人的解题报告,是把相符的人连一起,然后减去,其实就是最大独立集. 最大独立集=|G| ...
- UVA 12083 POJ 2771 Guardian of Decency
/* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...
随机推荐
- C++IO cin
cin cin.get() 每次只读缓冲区一个字符,不能接收空格 cin.getline() 读缓冲区一行,能够接收空格 cin.ignore(2) 忽略缓冲器2个字节 int i = cin.pee ...
- 第03章:MongoDB启动参数说明
①基本配置 --quiet # 安静输出 --port arg # 指定服务端口号,默认端口27017 --bind_ip arg # 绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默 ...
- Sprinig泛型依赖注入
在父类中建立关系 (spring4.x以上版本) package com.spring.annotation.generic; import org.springframework.beans.fac ...
- Nodejs入门【转载】保留备用
关于 本书致力于教会你如何用Node.js来开发应用,过程中会传授你所有所需的“高级”JavaScript知识.本书绝不是一本“Hello World”的教程. 状态 你正在阅读的已经是本书的最终版. ...
- struts1(一)流程分析
- Docker Compose部署lnmp
参考:https://github.com/micooz/docker-lnmp 一.简介 使用Dcoekr镜像部署lnmp(Linux.Nginx.MySQL.PHP7). 1.1 结构 app └ ...
- 1101 Quick Sort
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- spring boot jpa 多条件组合查询带分页的案例
spring data jpa 是一个封装了hebernate的dao框架,用于单表操作特别的方便,当然也支持多表,只不过要写sql.对于单表操作,jpake可以通过各种api进行搞定,下面是一个对一 ...
- POJ2270&&Hdu1808 Halloween treats 2017-06-29 14:29 40人阅读 评论(0) 收藏
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8565 Accepted: 3111 ...
- Scala_对象
对象 单例对象 Scala并没有提供Java那样的静态方法或静态字段,但是,可以采用 object关键字实现单例对象,具备和Java静态方法同样的功能. 可以看出,单例对象的定义和类的定义很相似,明显 ...