POJ1446 Girls and Boys
| Time Limit: 5000MS | Memory Limit: 10000K | |
| Total Submissions: 12747 | Accepted: 5678 |
Description
the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.
Input
the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:(0)
The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.
Output
Sample Input
7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0
Sample Output
5
2
Source
——————————————————————————————————
题目的意思是给出n个学生喜欢的关系,问最多选出多少个人没有喜欢关系
思路:求最大独立集,最大独立集=点数n-最大匹配数
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN=1000;
int uN,vN; //u,v数目
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];
bool used[MAXN];
int mat[MAXN];
int aa[MAXN];
struct area
{
int x1,x2,y1,y2;
} s[100005];
struct point
{
int x,y;
} p[100005]; bool dfs(int u)
{
int v;
for(v=0; v<vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=0; u<uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int n,m,x,y;
int cas=1;
while(~scanf("%d",&n))
{
memset(g,0,sizeof g);
for(int i=0; i<n; i++)
{
scanf("%d: (%d)",&x,&m);
for(int i=0; i<m; i++)
{
scanf("%d",&y);
g[x][y]=1;
}
}
uN=vN=n;
printf("%d\n",n-hungary()/2);
}
return 0;
}
POJ1446 Girls and Boys的更多相关文章
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- Girls and Boys
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- Girls and Boys(匈牙利)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)
称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- istio prometheus预警Prometheus AlertManager
1.安装alertmanager kubectl create -f 以下文件 alertmanager-templates.yaml.configmap.yaml.deployment.yaml.s ...
- windows上安装RabbitMQ
windows下 安装 rabbitMQ 及操作常用命令 rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.它遵循Mozilla Public License开源协议,采用 ...
- [Jmeter] 将参数从Jenkins传递给Jmeter
Configuration in Jmeter Configuration in Jenkins
- Linq去重 不用实现IEqualityComparer接口的方法超级简单
RskFactorRelation.Instance.GetCache<RskFactorRelation>(true).Where(x => !string.IsNullOrEmp ...
- proguard-rules.pro、混淆、导jar包
前记: 买了一个<精通Android Studio>本来最想看的是关于混淆导jar包的,哪知道没有,有点小失望. 好吧,自己来. 在用Android Studio开发的时候,把minify ...
- 实现SQL express版做自动备份数据库的方法
SQL Server 2005/2008 Express版没有代理组件,不支持维护计划.可以采用下面的办法实现每日备份: 一.在要备份的数据库中创建存储过程. 存储过程名称:sp_BackupData ...
- Oracle 12c的可插拔数据库PDB
1. 默认安装之后会有一个可插拔数据库:pdborcl 2. 启动根容器: [oracle@eric ~]$ export ORACLE_SID=orcl [oracle@eric ~]$ sqlpl ...
- 【转】先说IEnumerable,我们每天用的foreach你真的懂它吗?
[转]先说IEnumerable,我们每天用的foreach你真的懂它吗? 我们先思考几个问题: 为什么在foreach中不能修改item的值? 要实现foreach需要满足什么条件? 为什么Linq ...
- 弹出DIV锁定代码
<html> <head> <meta http-equiv="Content-Type" content="text/html; ch ...
- viewer.js使用
viewer GitHub 地址: JS 版本:https://github.com/fengyuanchen/viewerjs jQuery 版本:https://github.com/fengyu ...