ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
来源:互联网 发布:淘宝软件订购 编辑:程序博客网 时间:2024/05/17 04:32
Description
We need to guard a set of points of interest using sentry robots that can not move or turn. We can position a sentry at any position facing either north, south, east or west. Once a sentry is settled, it guards the points of interest that are infront of it. If two or more points are in the same row or column a single robot can guard them all. Unfortunately, there are also some obstacles that the robot cannot see through.
From a set of points of interest and obstacles lying on a grid, calculate the minimum number of robots needed to guard all the points. In order to guard a point of interest, a robot must be facing the direction of this point and must not be any obstacles in between.
Given the following grid, where # represents an obstacle and * a point of interest, the minimum number of robots needed is 2 (a possible position and orientation is shown using arrows for each robot). Note that this is not the actual input or output, just a figure.
For the following grid we need 4 robots because of the obstacles.
Input
The first line of the input has an integer C representing the number of test cases that follow. Before each test case there is an empty line.
For each case, the first line has 2 integers, Y and X, representing the height and width of the grid. The next line has an integer that indicates the number of points of interest P. The following P lines will have the positions py and px of the points of interest, one point per line. The next line has an integer that indicates the number of obstacles W. The following W lines will have the positions wy and wx of an obstacle, one per line.
Output
For each test case print the minimum number of robots needed to guard all the points of interest, one per line.
CONSTRAINTS:
Sample Input
24 642 22 44 24 432 33 34 34 561 21 32 42 23 34 322 33 2
Sample Output
2
4
#include <iostream>#include <string>#include <string.h>#include <cstdio>using namespace std;#define MAXN 100 + 10#define MAXNN 5000 + 10int row, col, p, w, n, m;int temp[MAXN][MAXN];int c[MAXNN][MAXNN];int x[MAXN][MAXN], y[MAXN][MAXN];int match[MAXNN];bool vis[MAXNN];void init(){memset(match, -1, sizeof(match));}void memxy(){n = m = 1;for (int i = 1; i <= row; i++){for (int j = 1; j <= col;){while (j <= col && temp[i][j] != -1){x[i][j] = n;j++;}while (j <= col && temp[i][j] == -1){j++;}n++;}}for (int i = 1; i <= col; i++){for (int j = 1; j <= row;){while (j <= row && temp[j][i] != -1){y[j][i] = m;j++;}while (j <= row && temp[j][i] == -1){j++;}m++;}}memset(c, 0, sizeof(c));for (int i = 1; i <= row; i++){for (int j = 1; j <= col; j++){if (temp[i][j] == 1){c[x[i][j]][y[i][j]] = 1;}}}}bool dfs(int u){for (int i = 1; i <= m; i++){if (c[u][i] && !vis[i]){vis[i] = true;if (match[i] == -1 || dfs(match[i])){match[i] = u;return true;}}}return false;}void solve(){int ans = 0;for (int i = 1; i <= n; i++){memset(vis, false, sizeof(vis));if (dfs(i)){ans++;}}cout << ans << endl;}void input(){ int t, x, y; scanf("%d", &t); while (t--) { init(); scanf("%d %d", &row, &col);memset(temp, 0, sizeof(temp)); scanf("%d", &p); for (int i = 1; i <= p; i++) { scanf("%d %d", &x, &y); temp[x][y] = 1; } scanf("%d", &w); for (int i = 1; i <= w; i++) { scanf("%d %d", &x, &y); temp[x][y] = -1; }memxy(); solve(); }}int main(){ input(); return 0;}
- ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
- [二分图最大匹配=最小覆盖点]uva12549 Sentry Robots
- 【uva 12549】Sentry Robots HDU 2119 (hdu 2119Matrix升级版) 最小点覆盖+二分图匹配
- 12549 - Sentry Robots (二分图匹配)
- UVA 12549 Sentry Robots 最小点集覆盖
- 二分图匹配 + 最小点覆盖
- 二分图匹配 --- 最小点覆盖
- Sentry Robots, ACM/ICPC SWERC 2012, UVa12549 【二分图】
- poj1463 二分图匹配的最小点覆盖
- hdu1150 二分图匹配的最小点覆盖
- Uva 12549 Sentry Robots 网络流 - 二分图匹配
- 二分图-最大匹配,最小路径覆盖,最小点覆盖
- uva 12549 Sentry Robots 最大二分匹配
- 二分图的最大匹配(最小路径覆盖,最小点覆盖)
- 二分图最大匹配,点的最小覆盖,最小路径覆盖
- 二分图最大匹配,点的最小覆盖,最小路径覆盖
- UVAlive 6156 Sentry Robots
- POJ1548 Robots【二分图最小路径覆盖】
- ios扫描公共区域内wifi信息
- ALSA声卡驱动中的DAPM详解之二:widget-具备路径和电源管理信息的kcontrol
- Java基础知识学习笔记——嵌套类(Nested Classes)
- Android之高仿手机QQ聊天
- SharedPreferences跨应用读取数据问题
- ACM->uvalive->Sentry Robots(二分图匹配的最小点覆盖)
- C++练习之程序编写
- IOS 如何获得 WIFI SSID
- SNMP用VC实现的方法
- apache和tomcat同时使用同一个端口
- win7 登陆机制Credential Provider
- Android 可随意拖动的悬浮窗体
- 海量数据处理面试题
- 新浪微博 2013 年 6 月的 API 变更将会带来哪些影响?