hdu2768Cat vs. Dog (反建法,最大独立集)
Cat vs. Dog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1520 Accepted Submission(s): 570
vote on which pets should stay and which should be forced to leave the show.
Each viewer gets to cast a vote on two things: one pet which should be kept on the show, and one pet which should be thrown out. Also, based on the universal fact that everyone is either a cat lover (i.e. a dog hater) or a dog lover (i.e. a cat hater), it has
been decided that each vote must name exactly one cat and exactly one dog.
Ingenious as they are, the producers have decided to use an advancement procedure which guarantees that as many viewers as possible will continue watching the show: the pets that get to stay will be chosen so as to maximize the number of viewers who get both
their opinions satisfied. Write a program to calculate this maximum number of viewers.
* One line with three integers c, d, v (1 ≤ c, d ≤ 100 and 0 ≤ v ≤ 500): the number of cats, dogs, and voters.
* v lines with two pet identifiers each. The first is the pet that this voter wants to keep, the second is the pet that this voter wants to throw out. A pet identifier starts with one of the characters `C' or `D', indicating whether the pet is a cat or dog,
respectively. The remaining part of the identifier is an integer giving the number of the pet (between 1 and c for cats, and between 1 and d for dogs). So for instance, ``D42'' indicates dog number 42.
* One line with the maximum possible number of satisfied voters for the show.
2
1 1 2
C1 D1
D1 C1
1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
1
3
#include<stdio.h>
#include<string.h>
struct nn
{
char love[5];
char hate[5];
}cat[505],dog[505];
int map[505][505],vist[505],match[505],dog_n;
int find(int i)
{
for(int j=1;j<=dog_n;j++)
if(!vist[j]&&map[i][j])
{
vist[j]=1;
if(match[j]==0||find(match[j]))
{
match[j]=i; return 1;
}
}
return 0;
}
int main()
{
int t,n,m,v,cat_n;
char ch1[5],ch2[5];
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&v);
cat_n=0; dog_n=0;
for(int i=1;i<=v;i++)
{
scanf("%s%s",ch1,ch2);
if(ch1[0]=='C')
{
strcpy(cat[++cat_n].love,ch1);
strcpy(cat[cat_n].hate,ch2);
}
else
{
strcpy(dog[++dog_n].love,ch1);
strcpy(dog[dog_n].hate,ch2);
}
}
memset(map,0,sizeof(map));
for(int i=1;i<=cat_n;i++)
for(int j=1;j<=dog_n;j++)
if(strcmp(cat[i].love,dog[j].hate)==0||strcmp(cat[i].hate,dog[j].love)==0)
map[i][j]=1;
memset(match,0,sizeof(match));
int ans=0;
for(int i=1;i<=cat_n;i++)
{
memset(vist,0,sizeof(vist));
ans+=find(i);
}
printf("%d\n",v-ans);
}
}
hdu2768Cat vs. Dog (反建法,最大独立集)的更多相关文章
- hdu2768-Cat vs. Dog:图论:二分匹配
Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Cat VS Dog HDU - 3829 (最大独立集 )
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- 线段树(结构体建法_QAQ)
线段树(结构体)模板 #include<iostream> #include<cstdio> #include<queue> #include<cstring ...
- hdu-2768-Cat vs. Dog(二分图-最大匹配数)
题意: 有猫C个和狗D个,有V个投票人,每个人喜欢猫讨厌狗或则喜欢狗讨厌猫! 求最多能满足多少投票人. 分析: 两个投票者矛盾的话就连一条边,总数减去最大匹配数/2就是要求的答案 // File Na ...
- L - Cat VS Dog - HDU 3829(最大独立集)
题意:有P个孩子,有的孩子喜欢猫不喜欢狗,有的喜欢狗不喜欢猫(喜欢的和不喜欢的一定是相相对立的动物),动物园有N只猫,M只狗,每个孩子都有喜欢的猫讨厌的狗(或者喜欢的狗讨厌的猫),现在动物园要送走一批 ...
- ACM-由数据范围反推算法复杂度以及算法内容
一般ACM或者笔试题的时间限制是1秒或2秒. 在这种情况下,C++代码中的操作次数控制在 \(10^7\) 为最佳. 下面给出在不同数据范围下,代码的时间复杂度和算法该如何选择: 数据范围 算法选择 ...
- HDU 4725 The Shortest Path in Nya Graph(spfa+虚拟点建图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:有n层,n个点分布在这些层上,相邻层的点是可以联通的且距离为c,还有额外给出了m个条边 ...
- 10月清北学堂培训 Day 3
今天是钟皓曦老师的讲授~ zhx:题很简单,就是恶心一些qwq~ T1 别人只删去一个字符都能AC,我双哈希+并查集只有40?我太菜了啊qwq 考虑到越短的字符串越难压缩,越长的字符串越好压缩,所以我 ...
- 个人训练记录(UPD 9.16)
本文章记录一些较难的题,摘自自己的blog中的其他文章.也有些单独成章有点浪费的题也写在里面了. 2019.7.15-2019.7.21 1182F(2900) 题意:求在区间 \([a,b]\) 中 ...
随机推荐
- RC Immix
目录 RC Immix 目的 合并型引用计数 伪代码 优点和缺点 合并型引用计数法和Immix的融合 新对象 被动的碎片整理 积极的碎片整理 优点和缺点 优点 缺点 RC Immix Rifat Sh ...
- ios 绘图,绘制坐标系,画坐标系
先来看个效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- OpenGl 坐标转换
1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观測变换(ModelView Transformation)和投影变换(Projection Transformation). 做个 ...
- 千千万万的IT开发project师路在何方
已经找不到该文章的最初出处了,有找到的人请告诉我.谢谢~~ 千千万万的IT开发project师路在何方 2007-06-25 21:41 恭喜,你选择开发project师作为自已的职业! 悲哀.你选择 ...
- 【python下使用OpenCV实现计算机视觉读书笔记2】图像与字节的变换
import cv2 import numpy import os # Make an array of 120,000 random bytes. randomByteArray = bytearr ...
- 学password学一定得学程序
题目描写叙述 以前.ZYJ同学非常喜欢password学.有一天,他发现了一个非常长非常长的字符串S1.他非常好奇那代表着什么,于是奇妙的WL给了他还有一个字符串S2.可是非常不幸的是,WL忘记跟他说 ...
- Servlet之doPost获取表单参数
/** * 获取表单参数 */ private void readForm() { // TODO Auto-generated method stub Enumeration e = request ...
- HTTP 与 HTTPS
https就是http和TCP之间有一层SSL层,这一层的实际作用是防止钓鱼和加密. 防止钓鱼通过网站的证书,网站必须有CA证书,证书类似于一个解密的签名. 另外是加密,加密需要一个密钥交换算法,双方 ...
- maven pom下载不了
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/m ...
- Android针对不同的手机屏幕大小设计图片资源与编码
注:本文转载于:http://blog.csdn.net/welovesunflower/article/details/7930248 一些术语 Screen Size 屏幕尺寸: 实际的物理尺寸, ...