题意:

有猫C个和狗D个,有V个投票人,每个人喜欢猫讨厌狗或则喜欢狗讨厌猫!

求最多能满足多少投票人。

分析:

两个投票者矛盾的话就连一条边,总数减去最大匹配数/2就是要求的答案

// File Name: ACM/HDU/2768.cpp
// Author: Zlbing
// Created Time: 2013年08月16日 星期五 15时14分15秒 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
const int MAXN=;
int Left[MAXN];//Left[i]为左边与右边第i个点匹配的编号
int w[MAXN][MAXN];
bool S[MAXN],T[MAXN];
int N;
bool match(int i)
{
S[i]=true;
for(int j=;j<=N;j++)if(w[i][j]&&!T[j])
{
T[j]=true;
if(Left[j]==||match(Left[j]))
{
Left[j]=i;
return true;
}
}
return false;
}
int hungry(){
CL(Left,);
int sum=;
for(int i=;i<=N;i++)
{
CL(S,);
CL(T,);
if(match(i))sum++;
}
return sum;
}
string A[MAXN],B[MAXN];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
REP(i,,k)
cin>>A[i]>>B[i];
CL(w,);
REP(i,,k)
REP(j,i+,k)
{
if(A[i]==B[j]||B[i]==A[j])
{
w[i][j]=w[j][i]=;
}
}
N=k;
int ans=k-hungry()/;
printf("%d\n",ans);
}
return ;
}

hdu-2768-Cat vs. Dog(二分图-最大匹配数)的更多相关文章

  1. HDU——2768 Cat vs. Dog

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  3. hdu 2768 Cat vs. Dog (二分匹配)

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. hdu 2768 Cat vs. Dog 最大独立集 巧妙的建图

    题目分析: 一个人要不是爱狗讨厌猫的人,要不就是爱猫讨厌狗的人.一个人喜欢的动物如果离开,那么他也将离开.问最多留下多少人. 思路: 爱猫和爱狗的人是两个独立的集合.若两个人喜欢和讨厌的动物是一样的, ...

  5. HDU - 3829 Cat VS Dog (二分图最大独立集)

    题意:P个小朋友,每个人有喜欢的动物和讨厌的动物.留下喜欢的动物并且拿掉讨厌的动物,这个小朋友就会开心.问最多有几个小朋友能开心. 分析:对于每个动物来说,可能既有人喜欢又有人讨厌,那么这样的动物实际 ...

  6. HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配)

    HDU 3829 Cat VS Dog / NBUT 1305 Cat VS Dog(二分图最大匹配) Description The zoo have N cats and M dogs, toda ...

  7. [HDU] 2063 过山车(二分图最大匹配)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2063 女生为X集合,男生为Y集合,求二分图最大匹配数即可. #include<cstdio> ...

  8. (hdu)2444 The Accomodation of Students 判断二分图+最大匹配数

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Problem Description There are a group of s ...

  9. HDU 3829 - Cat VS Dog (二分图最大独立集)

    题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...

随机推荐

  1. Asp.net Mvc 第二回 UrlRouting

    一.什么是UrlRouting 你可以使用UrlRouting来配置一些URL的映射,使用户可以按你的规则来访问网站. 使用UrlRouting,一定要规定URL模式,它包括一个位置标识,它将在你请求 ...

  2. css兼容性问题

    其实做网页最大的问题还是兼容性吧,要调试IE的各种浏览器. DIV+CSS设计IE6.IE7.FF 兼容性  DIV+CSS网页布局这是一种趋势,我也开始顺应这股趋势了,不过在使用DIV+CSS网站设 ...

  3. 开源的Android开发框架-------PowerFramework使用心得(五)网络请求HTTPRequest

    GET请求示例 //所有参数都使用Bundle,用putString Bundle bundle = new Bundle(); bundle.putString("username&quo ...

  4. C语言中,如何通过socket得到对端IP地址

    struct sockaddr_in clientaddr1; memset(&clientaddr1, 0x00, sizeof(clientaddr1)); socklen_t nl=si ...

  5. index full scan/index fast full scan/index range scan

    **************************1************************************* 索引状态:          valid.      N/A .    ...

  6. [C++]C++类基本语法

    本测试代码包括以下内容: (1)如何使用构造函数:(2)默认构造函数:(3)对象间赋值:(4)const使用语法:(5)定义类常量: 一种方法是用enum,另一种方法是使用static. #inclu ...

  7. SGU 130.Circle

    答案为Catalan数C(2k, k)/(k+1) #include <stdio.h> using namespace std; int k; int main() { scanf(&q ...

  8. nginx+php,502错误

    502错误基本就是php进程执行中挂了,其中有个原因就可能是进程执行超时设置导致的比如这个: ; The timeout for serving a single request after whic ...

  9. 解决Collection was modified; enumeration operation may not execute异常

    今天在使用foreach循环遍历list集合时,出现Collection was modified; enumeration operation may not execute.这个错误,查了半天才发 ...

  10. C#遍历窗体控件(原文出自http://www.liangshunet.com/ca/201403/286434593.htm)

    一.C#遍历窗体控件 主要遍历属于窗体(Form)的控件(Controls),假如窗体中有 Panel.Button 和 TextBox 控件,遍历代码如下: /// <summary> ...