HDU3829_Cat VS Dog
题目是这样的,给定一些人喜欢某只猫或者狗,讨厌某只猫或者狗。求最多能够同时满足多少人的愿望?
题目很有意思。建模后就很简单了。
对于同一只猫或者狗,如果有一个讨厌,另一个人喜欢,那么这两个连一条边。最终,最大独立集数等于最大匹配数就可以了。。
Orz。
召唤代码君:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define maxn 505
using namespace std; vector<int> likec[maxn],disc[maxn],liked[maxn],disd[maxn];
vector<int> v[maxn];
int n,m,p,ans,t1,t2;
int f[maxn],tag[maxn];
char s1[maxn],s2[maxn]; void init()
{
ans=0;
for (int i=1; i<=p; i++) v[i].clear(),f[i]=0,tag[i]=0;
for (int i=1; i<=n; i++) likec[i].clear(),disc[i].clear();
for (int i=1; i<=m; i++) liked[i].clear(),disd[i].clear();
} int num(char S[])
{
int cur=0;
for (int i=0; S[i]; i++) cur=cur*10+S[i]-'0';
return cur;
} int dfs(int cur,int T)
{
if (tag[cur]==T) return false;
else tag[cur]=T;
for (unsigned i=0; i<v[cur].size(); i++)
{
if (tag[v[cur][i]]==T) continue;
if (f[v[cur][i]]==0 || dfs(f[v[cur][i]],T))
{
f[v[cur][i]]=cur;
f[cur]=v[cur][i];
return true;
}
}
return false;
} int main()
{
while (scanf("%d%d%d",&n,&m,&p)!=EOF)
{
init();
for (int i=1; i<=p; i++)
{
scanf("%s%s",s1,s2);
t1=num(s1+1),t2=num(s2+1);
if (s1[0]=='C') likec[t1].push_back(i);
else liked[t1].push_back(i);
if (s2[0]=='C') disc[t2].push_back(i);
else disd[t2].push_back(i);
}
for (int i=1; i<=n; i++)
for (unsigned x1=0; x1<likec[i].size(); x1++)
for (unsigned x2=0; x2<disc[i].size(); x2++)
{
v[likec[i][x1]].push_back(disc[i][x2]);
v[disc[i][x2]].push_back(likec[i][x1]);
}
for (int i=1; i<=m; i++)
for (unsigned x1=0; x1<liked[i].size(); x1++)
for (unsigned x2=0; x2<disd[i].size(); x2++)
{
v[liked[i][x1]].push_back(disd[i][x2]);
v[disd[i][x2]].push_back(liked[i][x1]);
}
for (int i=1; i<=p; i++)
{
if (f[i]!=0) continue;
if (dfs(i,i)) ans++;
}
printf("%d\n",p-ans);
}
return 0;
}
HDU3829_Cat VS Dog的更多相关文章
- [ZigBee] 12、ZigBee之看门狗定时器——饿了就咬人的GOOD DOG
引言:硬件中的看门狗,不是门卫的意思,而是一只很凶的狗!如果你不按时喂它,它就会让系统重启!这反而是我们想要的功能~ 1.看门狗概述 看门狗定时器(WDT,Watch Dog Timer)是单片机的一 ...
- 斑点检测(LoG,DoG)(下)
斑点检测(LoG,DoG)(下) LoG, DoG, 尺度归一化 上篇文章斑点检测(LoG,DoG)(上)介绍了基于二阶导数过零点的边缘检测方法,现在我们要探讨的是斑点检测.在边缘检测中,寻找的是二阶 ...
- 斑点检测(LoG,DoG) [上]
斑点检测(LoG,DoG) [上] 维基百科,LoG,DoG,DoH 在计算机视觉中,斑点检测是指在数字图像中找出和周围区域特性不同的区域,这些特性包括光照或颜色等.一般图像中斑点区域的像素特性相似甚 ...
- ural 1246. Tethered Dog
1246. Tethered Dog Time limit: 1.0 secondMemory limit: 64 MB A dog is tethered to a pole with a rope ...
- Cat VS Dog
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- DoG 、Laplacian、图像金字塔详解
DoG(Difference of Gaussian) DoG (Difference of Gaussian)是灰度图像增强和角点检测的方法,其做法较简单,证明较复杂,具体讲解如下: Differe ...
- HDU 3289 Cat VS Dog (二分匹配 求 最大独立集)
题意:每个人有喜欢的猫和不喜欢的狗.留下他喜欢的猫他就高心,否则不高心.问最后最多有几个人高心. 思路:二分图求最大匹配 #include<cstdio> #include<cstr ...
- 编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish 和Dog,定义主类E,在其main方法中分别创建其对象并测试对象的特性。
package animal; public class Animal { //成员属性 private String kind; public String getKind() { return k ...
- sjtu1586 Dog
Description 隔壁村的阿黑的Dog没有跑, 但Dog已经15岁了, 相当于人类达到了79岁. 为了防止Dog患上犬类认知障碍 (Canine cognitive dysfunction, C ...
随机推荐
- [webpack]--webpack 如何解析代码模块路径
前言 webpack是如何解析代码模块路径 webpack 中有一个很关键的模块 enhanced-resolve 就是处理依赖模块路径的解析的,这个模块可以说是 Node.js 那一套模块路径解析的 ...
- Navigation - How to define the structure of the navigation tree via the NavigationItemAttribute
In the meantime, you should use the Model Editor to create such a navigation structure. There are se ...
- apache-日志-记录post数据
apache access.log日志只能打印出相关的头部信息,例如:Referer, User-agent.但是我希望看到body中的data. 目前找到解决方案是使用apache的扩展module ...
- 180803-Spring定时任务高级使用篇
Spring定时任务高级使用篇 前面一篇博文 <Spring之定时任务基本使用篇> 介绍了Spring环境下,定时任务的简单使用姿势,也留了一些问题,这一篇则希望能针对这些问题给个答案 I ...
- nGrinder性能测试平台的安装部署
1.从GitHub下载war包: https://github.com/naver/ngrinder/releases 2.把ngrinder-controller-3.4.2.war重命名为ngri ...
- EasyUI系列学习笔记(一)——注册
前面介绍过EasyUI是一个前段框架,开发之前需要导入底层包:我这里采用的是EasyUI 1.4版本~ 今天主要是搭建一个EasyUI的环境,同时做一个登陆页面... 环境搭建 导入需要的文件到项目中 ...
- Java 浅拷贝 深拷贝
两者区别主要在于引用数据类型的属性,对于基本数据类型采用的是值传递,所以两者一样: 对于浅拷贝,引用数据类型只会进行引用传递,即复制一份引用值(内存地址)给新对象,一个对象的变化会影响到另一个的引用属 ...
- Codeforces70 | Codeforces Beta Round #64 | 瞎讲报告
目录 前言 正文 A B C D E 前言 这个毒瘤的517 放了Div1 然后D题是昨天讲的动态凸包(啊喂!我还没来的及去写 结果自己想的是二分凸包 (当然没有写出来 写完前两题之后就愉快地弃疗 C ...
- mpstat命令详解
基础命令学习目录首页 原文链接:https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858775.html 简介 mpstat是Multipro ...
- CocoaPods :为iOS程序提供依赖管理的工具(yoowei)
修改于:2016.11.18 2017.1.10 2019.01.31 CocoaPods 源码 : https://github.com/CocoaPods/CocoaPods CocoaPo ...