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 (多校)

    题意:在网格里面给定了 横,竖 两种多米诺骨牌,同向的不可以覆盖,不同向的可以覆盖,问你最多去掉多少个有覆盖的多米诺,使得网格内剩余的多米诺骨牌最多 解题思路: 一.搜索 (1),分别对横竖两种不同的 ...

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

    把相互覆盖的骨牌放入一个集合中,如果一个集合有cnt 个元素  那么这个集合所在区域最多只能存在 (cnt +1)/2 个元素. #include <iostream> #include ...

  3. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

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

    题目链接:点击查看 题目大意:给出n只狗和m只猫,现在有p个小朋友,每个小朋友都有一只喜欢的猫和一只不喜欢的狗,或者有一只喜欢的狗和一只不喜欢的猫,如果一个小朋友喜欢的动物还在,不喜欢的动物走了,那么 ...

  5. HDU - 4612 Warm up(边双缩点+树的直径)

    题目链接:点击查看 题目大意:给出一个由n个点和m条边构成的无向图,现在允许加一条边,使得整张图中桥的数量最少,求最少的桥的数量 题目分析:因为是要求桥,所以直接用tarjan边双缩点,将原图转换成一 ...

  6. ACM 图论入门题(附代码解释)

    目录 HDU 1869 六度分离 HDU 1874 畅通工程续 (最短路) HDU 3339 In Action (最短路+01背包) HDU 1162 Eddy's picture(prime算法) ...

  7. 解题报告:【kuangbin带你飞】专题九 连通图

    目录 A.POJ 1236 Network of Schools(有向图缩点) B.UVA 315 Network(找割点) C.UVA 796 Critical Links(桥) D.POJ 369 ...

  8. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  9. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

最新文章

  1. mnn op name is empty or dup
  2. spring 配置文件 数据库引入
  3. 创建一个springMVC项目总结
  4. IP 地址编址方式(分类、子网划分、无分类)
  5. 魔方微店商城系统 v1
  6. 存储过程中调用EXECUTE IMMEDIATE的“权限不足”问题
  7. jdk,Eclipse,SWTDesigner安装【原创】
  8. 每日一题20180401-Linux
  9. linux企业版笔记之Samber服务的基本配置
  10. python如何运行js代码
  11. 17、【易混淆概念集】第十一章1 项目风险 风险临界值 VS 风险承受力 风险管理流程 风险管理及变更流程 规划风险管理 识别风险
  12. 刷题记录:牛客NC23803DongDong认亲戚
  13. 【PCL】NDT点云配准(Registration)
  14. 软考系统集成项目管理工程师全真模拟题
  15. 安装mysql_python
  16. 使用Java在浏览器页面无法导出excel表格
  17. “C++”读作「C 加加」,为什么“C♯”不能读作「C 井」呢?
  18. 当显示内容过多时的滚屏类Container.java
  19. 概率统计D 01.06 伯努利概型
  20. rtsp 客户端请求视频的时候顺便填写输入用户名和密码的格式

热门文章

  1. numpy.linalg.svd
  2. 在用户控件中弹出消息框的方法
  3. Vue之@click、事件修饰符@click.stop与@click.prevent、按键修饰符@keyup.enter
  4. python学习笔记之socket(第七天)
  5. 比较高明的暗部提亮方法:选取暗部,滤色叠加
  6. WPF以Clickonce方式发布后使用管理员身份运行
  7. mysql server驱动_oracle、mysql、sql server等;流行数据库的链接驱动配置
  8. linux程序已经在后台运行冻结了_linux 让程序在后台运行的几种可靠方法
  9. 爬虫python编程与cvi编程_与爬虫无关,简单的用python进行科学运算
  10. ioca0中断 pic单片机_关于PIC单片机的一些经验总结 -单片机-电子工程世界网