HDU 4619 Warm up 2 最大独立集
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 最大独立集的更多相关文章
- hdu 4619 Warm up 2_最大独立集
三个人整个下午都想不出这题 后来看题解,竟然用匈牙利算法的最大独立集,我顿时晕了. 题意:给竖着和横着的方块,除去重叠的,最多能留下几个方块 #include <cstdlib> #inc ...
- hdu 4619 Warm up 2(并查集)
借用题解上的话,就是乱搞题.. 题意理解错了,其实是坐标系画错了,人家个坐标系,我给当矩阵画,真好反了.对于题目描述和数据不符的问题,果断相信数据了(这是有前车之鉴的hdu 4612 Warm up, ...
- hdu 4619 Warm up 2
http://acm.hdu.edu.cn/showproblem.php?pid=4619 根据题意可知,每一个方格可能只被一个骨牌覆盖 可能被两个骨牌覆盖 也可能不被覆盖 有一个骨牌覆盖的方格(单 ...
- 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 ...
- hdu 4619 Warm up 2 ( 二分图最大匹配 )
题目:Warm up 2 题意:有横竖两种方式放着的多米诺骨牌,相同方向的不可能重叠,但是横放和竖放 的牌可能重叠.移走重叠的牌使剩下的牌最多. 分析:二分图匹配:最大独立集= ...
- hdu 4619 Warm up 2 (二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 题意: 平面上有一些1×2的骨牌,每张骨牌要么水平放置,要么竖直放置,并且保证同方向放置的骨牌不 ...
- hdu 4619 Warm up 2 网络流 最小割
题意:告诉你一些骨牌,然后骨牌的位置与横竖,这样求最多保留多少无覆盖的方格. 这样的话有人用二分匹配,因为两个必定去掉一个,我用的是最小割,因为保证横着和竖着不连通即可. #include <s ...
- hdu 4619 Warm up 2 二分图匹配
题目链接 给两种长方形, 水平的和垂直的, 大小都为1*2, n个水平的, m个垂直的, 给出它们的坐标. 水平的和垂直的可以相互覆盖, 但是同种类型的没有覆盖. 去掉一些长方形, 使得剩下的全部都没 ...
- HDU 4619 Warm up 2 贪心或者二分图匹配
给同一张横着的牌的所在的格子编同一样的号,这些格子对应x集合,给同一张竖着的牌所在的格子编同一样的号,对应y集合,同一个格子上既有横着的牌又有竖着的牌,那么就建一条边,有冲突就要拿走一张,结果是总的牌 ...
随机推荐
- 「caffe编译bug」.build_release/lib/libcaffe.so: undefined reference to cv::imread
转自:https://www.douban.com/note/568788483/ CXX/LD -o .build_release/tools/convert_imageset.bin.build_ ...
- centos-testlink安装使用手册
1.新建虚拟机设置 网卡必须选择ovirtmgmt模式 2.Centos6.3系统安装 说明: 1.CentOS 6.3系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.3-i386-bin ...
- SwitchSharp代理插件的安装和使用
参考链接: http://bbs.feng.com/read-htm-tid-8227283.html 安装参考链接: http://jingyan.baidu.com/article/380abd0 ...
- JSP基础与提高(一).md
JSP基础 JSP的由来 1.1. 为什么有JSP规范 Servlet技术产生以后,在使用过程中存在一个很大的问题,即为了表现页面的效果而需要输出大量的HTML标签,这些标签在Servlet中表现为一 ...
- HEVC代码记录(删除)
得到编码残差 TEncSearch.cpp 4543:rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
- js中的for循环
预定义: var arr=[22,33,12,34];//数组(特殊的对象) var obj={ //对象 name:"Jack", age:"99", sex ...
- 大理石在哪儿(UVa10474)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&a ...
- 使用递归计算n的阶乘n!
计算n! 观察公式2可以直接使用递归求解 C++代码如下: #include <iostream> using namespace std; unsigned func(unsigned ...
- 一、React Native 搭建开发环境(1)(Mac OS - IOS项目篇)
React Native是Facebook推出的一个开发IOS和安卓APP的技术.至于更多的详情,这里不再描述,大家可以自行百度它的定义. 原因:由于我想在一台电脑上同时开发IOS和Android两个 ...
- 四 Python基础
Python是一种计算机编程语言.计算机编程语言和我们日常使用的自然语言有所不同,最大的区别就是,自然语言在不同的语境下有不同的理解,而计算机要根据编程语言执行任务,就必须保证编程语言写出的程序决不能 ...