hdu3829
题解:
对于每一个孩子裂点+建边
如果i孩子讨厌的和j孩子喜欢的相同,那么建边
然后跑最大独立集
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=;
int fi[N],num,s1[N],s2[N],match[N],zz[N*N],ne[N*N],n,f[N];
void jb(int x,int y)
{
ne[++num]=fi[x];
fi[x]=num;
zz[num]=y;
}
int dfs(int x)
{
for (int i=fi[x];i;i=ne[i])
if (!f[zz[i]])
{
f[zz[i]]=;
if (!match[zz[i]]||dfs(match[zz[i]]))
{
match[zz[i]]=x;
return ;
}
}
return ;
}
int read()
{
int k=,x=;char c;
for (c=getchar();c!='C'&&c!='D';c=getchar());
if (c=='C')k+=n;
scanf("%d",&x);
return k+x;
}
int main()
{
while (~scanf("%d%d%d",&n,&n,&n))
{
memset(fi,,sizeof fi);
memset(match,,sizeof match);
num=;
for (int i=;i<=n;i++)s1[i]=read(),s2[i]=read();
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
if (s1[i]==s2[j]||s2[i]==s1[j])jb(i,j);
int ans=;
for (int i=;i<=n;i++)
{
memset(f,,sizeof f);
ans+=dfs(i);
}
printf("%d\n",n-ans/);
}
}
hdu3829的更多相关文章
- HDU3829 Cat VS Dog —— 最大独立集
题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU3829 Cat VS Dog
题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...
- hdu3829(最大独立集)
传送门:Cat VS Dog 题意:动物园有N只猫,M只狗,P个小孩.每个小孩都有自己喜欢的动物和讨厌的动物,如果他喜欢狗,那么就讨厌猫, 如果他讨厌狗,那么他就喜欢猫.某个小孩能开心,当且仅当他喜欢 ...
- hdu3829最大独立集
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-a ...
- Hdu3829 Cat VS Dog(最大独立点集)
Cat VS Dog Problem Description The zoo have N cats and M dogs, today there are P children visiting t ...
- HDU3829(KB10-J 二分图最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- HDU3829:Cat VS Dog(最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- hdu3829 二分匹配 最大独立集
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
随机推荐
- Spring-1-I 233 Matrix(HDU 5015)解题报告及测试数据
233 Matrix Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descript ...
- DevOps简单介绍
jenkins作为测试环境代码发布工具,sonar作为静态代码检查工具,idea作为开发工具,jira作为缺陷管理平台,upstream作为code review工具(正在研究).DevOps最近比较 ...
- Python Date 1–Hello world print
对比学习Python与C str1 = 'hello python 2'# 字符串i = 3.1415926535 print(str1)print("hello python\n" ...
- Error: Flash Download failed - "Cortex-M0"
今天在调试程序时.DEMO板下载几次后就提示Flash下载失败: Keil v4里面的设置都没有动过.不可能被修改.此时.使用新唐的ICP Progra ...
- Windows7使用无线网卡建立WiFi热点
在Windows7下设置热点需要用到命令netsh wlan,具体的设置步骤如下: 1.配置热点 以管理员身份打开命令行模式,输入命令 netsh wlan set hostednetwork mod ...
- 配置ssh秘钥登陆
环境2台linux服务器:node1 192.168.X.234 node2 192.168.X.242 演示用node1无密码登陆node ...
- MySQL日常维护
删除MySQL 账号 use mysql delete from user where user='xiewenming'; 授权账号密码 GRANT SELECT,INSERT,UPDATE,DEL ...
- spring boot 集成kafka (多线程,消费者使用kafka的原生api实现,因为@KakfkaListener修改groupId无效)
application-test.properties #kafka kafka.consumer.zookeeper.connect=*:2181 kafka.consumer.servers=*: ...
- 安装GoMap
参考:https://github.com/ehrudxo/GoMap 1.依赖go包安装 gorm包安装 直接在github首页搜索gorm,找到对应的gorm包: 然后打开本机cmd命令行窗口,切 ...
- codeforces27D Ring Road 2
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...