hdu 2768(建图,最大点独立集)
Cat vs. Dog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2030 Accepted Submission(s): 774
latest reality show has hit the TV: ``Cat vs. Dog''. In this show, a
bunch of cats and dogs compete for the very prestigious Best Pet Ever
title. In each episode, the cats and dogs get to show themselves off,
after which the viewers 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.
1 1 2
C1 D1
D1 C1
1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
3
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
int c,d,v;
char a[N][],b[N][];
int graph[N][N];
int linker[N];
bool vis[N];
bool dfs(int u){
for(int i=;i<=v;i++){
if(graph[u][i]&&!vis[i]){
vis[i] = true;
if(linker[i]==-||dfs(linker[i])){
linker[i] = u;
return true;
}
}
}
return false;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d%d",&c,&d,&v);
for(int i=;i<=v;i++){
scanf("%s%s",a[i],b[i]);
}
memset(graph,,sizeof(graph));
for(int i=;i<=v;i++){
for(int j=;j<=v;j++){
if(strcmp(a[i],b[j])==||strcmp(a[j],b[i])==){
graph[i][j] = graph[j][i] = ;
}
}
}
int res = ;
memset(linker,-,sizeof(linker));
for(int i=;i<=v;i++){
memset(vis,false,sizeof(vis));
if(dfs(i)) res++;
}
printf("%d\n",v-res/);
}
return ;
}
hdu 2768(建图,最大点独立集)的更多相关文章
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- HDU 4725 建图
http://acm.hdu.edu.cn/showproblem.php?pid=4725 The Shortest Path in Nya Graph Time Limit: 2000/1000 ...
- hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)
Walk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- Food HDU - 4292 网络流 拆点建图
http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...
- hdu 2647 (拓扑排序 邻接表建图的模板) Reward
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...
- HDU 4370 0 or 1(spfa+思维建图+计算最小环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4370 题目大意:有一个n*n的矩阵Cij(1<=i,j<=n),要找到矩阵Xij(i< ...
- HDU 4725 The Shortest Path in Nya Graph(spfa+虚拟点建图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:有n层,n个点分布在这些层上,相邻层的点是可以联通的且距离为c,还有额外给出了m个条边 ...
- HDU 3639 Hawk-and-Chicken(强连通缩点+反向建图)
http://acm.hdu.edu.cn/showproblem.php?pid=3639 题意: 有一群孩子正在玩老鹰抓小鸡,由于想当老鹰的人不少,孩子们通过投票的方式产生,但是投票有这么一条规则 ...
- hdu 5294 Tricks Device 最短路建图+最小割
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Tricks Device Time Limit: 2000/1000 MS (Java/Other ...
随机推荐
- Warning: Received `false` for a non-boolean attribute `xxx`.
React对boolean类型的attribute的识别方式问题,可以采用以下方法解决: xxx={value ? 1 : 0} 改成数字的写法,不用布尔值. 具体可以参考:https://githu ...
- Android Json解析与总结
一.JSON定义 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...
- mapper的前后缀
1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=&quo ...
- HDU1078记忆化搜索
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- kubernetes创建资源对象yaml文件例子--pod详解
apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中 kind: Pod #指定创建资源的角色/类型 metadata: #资源的元数据/属性 name: ...
- 第三方库升级Nginx
通过PPA方式,来升级Nginx 1. 添加PPA sudo add-apt-repository ppa:nginx/stable sudo apt-get updatesudo apt-get u ...
- Nginx与Apache工作方式
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://going.blog.51cto.com/7876557/1304204 Ngin ...
- 阿里C++研发实习二面和三面面经
下午连着面了阿里爸爸的二面和三面,非常不明白别人的三面都是hr了,为什么我还是在技术面,难道面了个假阿里.不管怎么样,来篇面经攒攒人品. 二面 第一次遇到这么严肃的面试官,居然可以全程无表情的,面了这 ...
- 数据结构:Treap
关于重量平衡树的相关概念可以参考姊妹文章:重量平衡树之替罪羊树 Treap是依靠旋转来维护平衡的重量平衡树中最为好写的一中,因为它的旋转不是LL就是RR 对于每一个新的节点,它给这个节点分配了一个随机 ...
- vijos 1471 线性DP+贪心
描述 Orz教主的成员为教主建了一个游乐场,在教主的规划下,游乐场有一排n个弹性无敌的跳跃装置,它们都朝着一个方向,对着一个巨大的湖,当人踩上去装置可以带你去这个方向无限远的地方,享受飞行的乐趣.但是 ...