Warm up 2

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 28    Accepted Submission(s): 8

Problem Description
  Some 1×2 dominoes are placed on a plane. Each dominoe is placed either horizontally or vertically. It's guaranteed the dominoes in the same direction are not overlapped, but horizontal and vertical dominoes may overlap with each other. You task is to remove some dominoes, so that the remaining dominoes do not overlap with each other. Now, tell me the maximum number of dominoes left on the board.
 
Input
  There are multiple input cases.
  The first line of each case are 2 integers: n(1 <= n <= 1000), m(1 <= m <= 1000), indicating the number of horizontal and vertical dominoes.
Then n lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x + 1, y).
  Then m lines follow, each line contains 2 integers x (0 <= x <= 100) and y (0 <= y <= 100), indicating the position of a horizontal dominoe. The dominoe occupies the grids of (x, y) and (x, y + 1).
  Input ends with n = 0 and m = 0.
 
Output
  For each test case, output the maximum number of remaining dominoes in a line.
 
Sample Input
2 3
0 0
0 3
0 1
1 1
1 3
4 5
0 1
0 2
3 1
2 2
0 0
1 0
2 0
4 1
3 2
0 0
 
Sample Output
4
6
 
Source
 
Recommend
zhuyuanchen520
 

相当于求最大独立集。

顶点数-二分匹配数

#include<stdio.h>

#include<iostream>

#include<algorithm>

#include<string.h>

#include<vector>

using namespace std;

//************************************************

const int MAXN=;//这个值要超过两边个数的较大者,因为有linker
int linker[MAXN];
bool used[MAXN];
vector<int>map[MAXN];
int uN;
bool dfs(int u)
{
for(int i=;i<map[u].size();i++)
{
if(!used[map[u][i]])
{
used[map[u][i]]=true;
if(linker[map[u][i]]==-||dfs(linker[map[u][i]]))
{
linker[map[u][i]]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int u;
int res=;
memset(linker,-,sizeof(linker));
for(u=;u<uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
pair<int,int>p1[MAXN];
pair<int,int>p2[MAXN];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m;
int x,y;
while(scanf("%d%d",&n,&m)==)
{
if(n== &&m==)break;
for(int i = ;i < n;i++)
{
scanf("%d%d",&x,&y);
p1[i]= make_pair(x,y);
}
for(int i = ;i < m;i++)
{
scanf("%d%d",&x,&y);
p2[i]= make_pair(x,y);
}
uN = n;
for(int i = ;i < n;i++)
map[i].clear();
for(int i = ;i < n;i++)
{
for(int j = ;j < m;j++)
{
int x1 = p1[i].first;
int y1 = p1[i].second;
int x2 = p2[j].first;
int y2 = p2[j].second;
if( (x1==x2 && y1==y2)
||(x1==x2 && y1==y2+)
||(x1+==x2 && y1==y2)
||(x1+==x2 && y1==y2+)
)
map[i].push_back(j);
}
}
int ans = n+m-hungary();
printf("%d\n",ans);
}
return ;
}

HDU 4619 Warm up 2(2013多校2 1009 二分匹配)的更多相关文章

  1. HDU 4612 Warm up(2013多校2 1002 双连通分量)

    Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Su ...

  2. HDU 4704 Sum (2013多校10,1009题)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submi ...

  3. hdu 4619 Warm up 2(并查集)

    借用题解上的话,就是乱搞题.. 题意理解错了,其实是坐标系画错了,人家个坐标系,我给当矩阵画,真好反了.对于题目描述和数据不符的问题,果断相信数据了(这是有前车之鉴的hdu 4612 Warm up, ...

  4. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  5. HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  6. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  7. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  8. hdu 4619 Warm up 2 (二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...

  9. HDU 4619 Warm up 2 最大独立集

    Warm up 2 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4619 Description Some 1×2 dominoes are pla ...

随机推荐

  1. 函数lock_rec_get_n_bits

    /*********************************************************************//** Gets the number of bits i ...

  2. 解同余式ax ≡ c(mod m)

    将式子变形为 ax-c=my 可以看出原式有解当且仅当线性方程ax-my=c有解 设g = gcd(a, m) 则所有形如ax-my的数都是g的倍数 因此如果g不整除c则原方程无解. 下面假设g整除c ...

  3. wordpress plugins collection

    1/ simple page ordering 4.8星 wordpress的plugins唯一的好处就是命名简单易懂,这款插件从名称就可以看出来,用来对page页面排序的.只需要在后台page中拖拽 ...

  4. 切记一定要防止恶意用户直接访问Ajax请求地址

    多年前的一个web项目, 有一个地方是用ajax发送短信验证码, 当时没考虑好, 没判断来路, 这几天被人恶意滥用发送了很多垃圾短信, 投诉到公司来了.  今天一看代码吓出一身冷汗! 以后一定要记得判 ...

  5. 【自动化测试】Selenium处理富文本框

    http://blog.csdn.net/fudax/article/details/8089404 selenium处理富文本框,日历控件等 调用JS修改value值 document.getEle ...

  6. Java中数组复制的几种方法

    /** * @author zhengbinMac */ public class Test { public static void main(String[] args) { int[] arra ...

  7. js COOKIE 记住帐号或者uuid

    当开始接到这个任务的时候,我对cookie还是没多少了解的,而uuid的生成也是一无所知.但是当你发现这个网址http://stackoverflow.com/questions/105034/how ...

  8. Java 中方法的重载

    问: 什么是方法的重载呢? 答: 如果同一个类中包含了两个或两个以上方法名相同.方法参数的个数.顺序或类型不同的方法,则称为方法的重载,也可称该方法被重载了.如下所示 4 个方法名称都为 show , ...

  9. html asp php java 清除缓存

    HTML页面 <META HTTP-EQUIV="pragma" CONTENT="no-cache"><META HTTP-EQUIV=&q ...

  10. min_free_kbytes

    http://kernel.taobao.org/index.php?title=Kernel_Documents/mm_sysctl min_free_kbytes 先看官方解释:This is u ...