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#多线程编程实战(原书第二版)文摘
Thread t = new Thread(PrintNumbersWithDelay); t.Start(); t.Join(); 但我们在主程序中调用了t.Join方法,该方法允许我们等待直到线程 ...
- java Concurrent包学习笔记(七):ConcurrentHashMap
(注意:以下讲解的ConcurrentHashMap是jdk 1.8的) 一.ConcurrentHashMap的数据结构 ConcurrentHashMap在1.8中的实现,相比于1.7的版本基本上 ...
- c#委托与事件2
首先是一个关机器的一般方法: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- python3.4读取excel数据绘图
#!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...
- TensorFlow 实现 RNN 入门教程
转子:https://www.leiphone.com/news/201705/zW49Eo8YfYu9K03J.html 最近在看RNN模型,为简单起见,本篇就以简单的二进制序列作为训练数据,而不实 ...
- canvas制作表盘
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- xslt 简单的语法
1. 循环 <xsl:for-each select="catalog/cd"> 1 </xsl:for-each> 2. 定义变量赋值使用 <xsl ...
- 冬瓜头答疑:磁盘阵列内部FC-AL的性能问题
冬瓜头答疑:磁盘阵列内部FC-AL的性能问题 作者:冬瓜头出处:IT专家网2009-08-03 09:59 问: 大多数磁盘阵列都是通过两个控制器后端的端口,组成1/2/4条FC-AL环,来连接所 ...
- webView自适应及缩放
WebView wv=(WebView) findViewById(R.id.webView); wv.setVisibility(WebView.VISIBLE); WebSettings ws = ...
- Curl工具的使用
Curl命令可以通过命令行的方式,执行Http请求.在Elasticsearch中有使用的场景,因此这里研究下如何在windows下执行curl命令. 工具下载 在官网处下载工具包:http:// ...