Girls and Boys(poj 1466)
题目描述:
给出一系列男女配对意愿信息。求一个集合中的最大人数,满足这个集合中两两的人不能配对。
/*
二分图的最大独立集
因为没有给出具体的男生和女生,所以可以将数据扩大一倍,即n个男生,n个女生,
根据定理,最大独立集=总数-匹配数(本题应该除以2)
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 510
using namespace std;
int a[N][N],used[N],belong[N],n;
bool find(int i)
{
for(int j=;j<=n;j++)
if(a[i][j]&&!used[j])
{
used[j]=;
if(!belong[j]||find(belong[j]))
{
belong[j]=i;
return true;
}
}
return false;
}
void work()
{
for(int i=;i<=n;i++)
{
int x,m;scanf("%d: (%d)",&x,&m);x++;
for(int j=;j<=m;j++)
{
int y;scanf("%d",&y);y++;
a[x][y]=a[y][x]=;
}
}
int tot=;
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(find(i))tot++;
}
printf("%d\n",n-tot/);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(belong,,sizeof(belong));
work();
}
return ;
}
Girls and Boys(poj 1466)的更多相关文章
- Girls and Boys POJ - 1466 【(二分图最大独立集)】
Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- poj 1466 Girls and Boys 二分图的最大匹配
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- POJ 1466 Girls and Boys (匈牙利算法 最大独立集)
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 10912 Accepted: 4887 D ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- poj 1466 Girls and Boys (最大独立集)
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...
- POJ 1466:Girls and Boys 二分图的最大点独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11097 Accepted: 4960 D ...
- POJ Girls and Boys (最大独立点集)
Girls and Boys Time Limit: 5000MS Memo ...
随机推荐
- NOIP2008普及组题解
NOIP2008普及组题解 从我在其他站的博客直接搬过来的 posted @ 2016-04-16 01:11 然后我又搬回博客园了233333 posted @ 2016-06-05 19:19 T ...
- POJ2263 Heavy Cargo
Heavy Cargo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4004 Accepted: 2124 Descr ...
- POJ3259Wormholes(判断是否存在负回路)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38300 Accepted: 14095 Descr ...
- jQuery插件开发教程
jQuery插件开发教程 ——让你的jQuery水平提升一个台阶 要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台 ...
- .htaccess文件详解
启用.htaccess,需要修改httpd.conf,启用AllowOverride,并可以用AllowOverride限制特定命令的使用 笼统地来说,.htaccess可以帮我们实现包括:文件夹密码 ...
- mysql 用户方面的操作
1.只新建用户的操作 mysql -u root -p密码mysql> insert into mysql.user(Host,User,Password) values(‘localhost’ ...
- Android打电话&发短信
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView ...
- TFS2008解除独占式锁定文件命令(转载)
使用场景:如果项目团队成员A对项目某个文件以独占式方式签出,恰好那天该成员A没有来上班而成员需要对此文件进入修改并check in,这时需要先把A对该文件的锁定解除.没有IDE可以使用,只能使用下面的 ...
- 游标、动态sql、异常
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlIAAAFeCAIAAADBl2bCAAAgAElEQVR4nOyddXgU197H12OEELxIkV
- JNI的某些数组和字符串类型转换
JNICC++C#Windows jbytearray转c++byte数组 jbyte * arrayBody = env->GetByteArrayElements(data,0); jsiz ...