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集合,同一个格子上既有横着的牌又有竖着的牌,那么就建一条边,有冲突就要拿走一张,结果是总的牌 ...
随机推荐
- Spring Boot企业级博客系统实战视频教程
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- perl6正则 5: [ ] / | / ||
也就是可以把多种要匹配的写进[ ] 中, 第种用 | 分开就行了. | 与 || 有差别 |的话, 当匹配位置 相同时, 会取最长的, 而 || , 当前面的匹配成功, 后面的就不会再去匹配. / / ...
- python基础===拆分字符串,和拼接字符串
给定某字符,只需要保留其中的有效汉字或者字母,数字之类的.去掉特殊符号或者以某种格式进行拆分的时候,就可以采用re.split的方法.例如 ============================== ...
- 64_t5
texlive-mkpattern-svn15878.1.2-33.fc26.2.noarch..> 24-May-2017 15:54 38178 texlive-mkpic-bin-svn3 ...
- Linux 上配置 NTP SERVER
在CENTOS 6.2上面安装配置NTP SERVER 安装NTP:yum install ntp 配置时间源vi /etc/ntp.confserver 210.72.145.44server nt ...
- 使用正则表达式匹配IP地址
IP地址分为4段,以点号分隔.要对IP地址进行匹配,首先要对其进行分析,分成如下部分,分别进行匹配: 第一步:地址分析,正则初判 1.0-9 \d 进行匹配 2.10-99 [1-9]\d 进行匹 ...
- ASP.NET Core 2.0 MVC 发布部署--------- linux安装.NET CORE SDK具体操作链接以及操作总细节
具体链接:https://www.microsoft.com/net/learn/get-started/linuxubuntu 如下图:
- mysql delete 注意
mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值 ...
- HDU 1024 Max Sum Plus Plus(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1024 题目大意:有多组输入,每组一行整数,开头两个数字m,n,接着有n个数字.要求在这n个数字上,m块 ...
- Hadoop案例(九)流量汇总案例
流量汇总程序案例 1.自定义输出 统计手机号耗费的总上行流量.下行流量.总流量(序列化) 1)需求: 统计每一个手机号耗费的总上行流量.下行流量.总流量 2)数据准备 phone_date.txt - ...