Warm up 2

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=4619

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

Hint

题意

现在有1*2的纸牌

有n个是竖着放置的,有m个数平行放置的

他们可能是压在一起的,现在让你拿起来一些,使得纸牌互相不重叠

问你平面上最多还剩下多少个

题解:

把压在一起的建一条边,显然答案就是最大独立点集

代码

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e3 + 15;
pair < int , int > p[maxn];
int n , m , mat[105][105] , Left[maxn] , vis[maxn];
vector < int > e[maxn]; int dfs(int x){
for(auto it : e[x]){
if(Left[it] == -1){
Left[it] = x;
return 1;
}
if(vis[it]) continue;
vis[it] = 1;
if(dfs(Left[it])){
Left[it] = x;
return 1;
}
}
return 0;
} int main(int argc,char *argv[]){
while(scanf("%d%d",&n,&m)){
if( n == m && n == 0 ) break;
memset( mat , 0 , sizeof( mat ) );
for(int i = 1 ; i <= n ; ++ i){
int x , y ;
scanf("%d%d",&x,&y);
p[i].first = x , p[i].second = y;
}
for(int i = 1 ; i <= m ; ++ i){
int x , y ;
scanf("%d%d" , &x , & y);
mat[x][y] = mat[x][y+1] = i;
}
memset( Left , -1 , sizeof( Left ) );
for(int i = 1 ; i <= n ; ++ i){
e[i].clear();
int x = p[i].first;
int y = p[i].second;
if(mat[x][y]) e[i].push_back(mat[x][y]);
if(mat[x+1][y]) e[i].push_back(mat[x+1][y]);
}
int match = 0;
for(int i = 1 ; i <= n ; ++ i){
memset( vis , 0 , sizeof( vis ) );
match += dfs( i );
}
printf("%d\n" , n + m - match );
}
return 0;
}

HDU 4619 Warm up 2 最大独立集的更多相关文章

  1. hdu 4619 Warm up 2_最大独立集

    三个人整个下午都想不出这题 后来看题解,竟然用匈牙利算法的最大独立集,我顿时晕了. 题意:给竖着和横着的方块,除去重叠的,最多能留下几个方块 #include <cstdlib> #inc ...

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

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

  3. hdu 4619 Warm up 2

    http://acm.hdu.edu.cn/showproblem.php?pid=4619 根据题意可知,每一个方格可能只被一个骨牌覆盖 可能被两个骨牌覆盖 也可能不被覆盖 有一个骨牌覆盖的方格(单 ...

  4. HDU 4619 Warm up 2(2013多校2 1009 二分匹配)

    Warm up 2 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total S ...

  5. hdu 4619 Warm up 2 ( 二分图最大匹配 )

    题目:Warm up 2 题意:有横竖两种方式放着的多米诺骨牌,相同方向的不可能重叠,但是横放和竖放             的牌可能重叠.移走重叠的牌使剩下的牌最多. 分析:二分图匹配:最大独立集= ...

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

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

  7. hdu 4619 Warm up 2 网络流 最小割

    题意:告诉你一些骨牌,然后骨牌的位置与横竖,这样求最多保留多少无覆盖的方格. 这样的话有人用二分匹配,因为两个必定去掉一个,我用的是最小割,因为保证横着和竖着不连通即可. #include <s ...

  8. hdu 4619 Warm up 2 二分图匹配

    题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...

  9. HDU 4619 Warm up 2 贪心或者二分图匹配

    给同一张横着的牌的所在的格子编同一样的号,这些格子对应x集合,给同一张竖着的牌所在的格子编同一样的号,对应y集合,同一个格子上既有横着的牌又有竖着的牌,那么就建一条边,有冲突就要拿走一张,结果是总的牌 ...

随机推荐

  1. 摘: 给Shapre命名

    有两种解决方式: 在 VBA 中将slide中的Shape命名,改变shape.name即可. 另外一种方式就是有点投机取巧:你可以点击shap,右键选择web/alternativetext做些标记 ...

  2. 【UOJ#38】【清华集训2014】奇数国

    考虑欧拉函数的性质,60很小,压位存下线段树每个节点出现质数. #include<bits/stdc++.h> ; ; typedef long long ll; using namesp ...

  3. Python递归 — — 二分查找、斐波那契数列、三级菜单

    一.二分查找 二分查找也称之为折半查找,二分查找要求线性表(存储结构)必须采用顺序存储结构,而且表中元素顺序排列. 二分查找: 1.首先,将表中间位置的元素与被查找元素比较,如果两者相等,查找结束,否 ...

  4. 手机页面或是APP中减少使用setTimeout和setInterval,因为他们会导致页面卡顿

    1.setTimeout致使页面的卡顿或是不流畅,打乱模块的生命周期 ,还有setTimeout其实是很难调试的. 当一个页面有众多js代码的时候,setTimeout就是导致页面的卡顿. var s ...

  5. 转:google测试分享-问题和挑战

    原文: http://blog.sina.com.cn/s/blog_6cf812be0102vxer.html 前言:这个系列分享的内容大部分都是出自于<google是如何测试的>的书, ...

  6. Photon3Unity3D.dll 解析三——OperationRequest、OperationResponse

    OperationRequest 代表Operation操作的Request,包含Code和Parameters OperationCode  Byte类型的值,代表操作,由LiteOpCode定义了 ...

  7. Char 与 Byte

    var c: Char; b: Byte; begin c := 'A'; ShowMessage(c); //A b := ; ShowMessage(IntToStr(b)); c := Chr( ...

  8. 《数据结构与STL-第二章 线性表》读书笔记

    线性表 定义 线性表(linear list)是由零个或多个相同类型的数据元素构成的有限序列. 存储结构 顺序存储 最简单的存储方法是顺序存储法,即把线性表的数据元素按照逻辑次序顺序地放在一组地址连续 ...

  9. MINIBASE源代码阅读笔记之buffer manager

    BufDesc frame 们的 descriptor(见BufHashTbl注释),包括 pageNo: 这个 frame 在文件里的id,page number prevframe: -1 表示此 ...

  10. 【严蔚敏】【数据结构(C语言版)】 求n的阶乘

    阶乘函数为: 使用递归即可求得. #include <stdio.h> #include <stdlib.h> int Fact(int m){ ) ; ); //递归求阶乘 ...