12549 - Sentry Robots

Time limit: 1.000 seconds

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 gure.
For the following grid we need 4 robots because of the obstacles.
Input
The rst 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 rst 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:
1 C 50
1 Y; X 100
0 P Y X
0 W Y X
0 P + W Y X
1 px; wx X
1 py; wy Y
Sample Input
2
4 6
4
2 2
2 4
4 2
4 4
3
2 3
3 3
4 3
4 5
6
1 2
1 3
2 4
2 2
3 3
4 3
2
2 3
3 2
Sample Output
2
4

正解好像是二分图匹配,然而我直接贪了一贪,可能是数据水,思路见代码。

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <cstdlib>
  7. #include <string>
  8. #include <vector>
  9. #include <map>
  10. #include <set>
  11. #include <queue>
  12. #include <stack>
  13. #include <algorithm>
  14. using namespace std;
  15. #define ll long long
  16. #define _cle(m, a) memset(m, a, sizeof(m))
  17. #define repu(i, a, b) for(int i = a; i < b; i++)
  18. #define repd(i, a, b) for(int i = b; i >= a; i--)
  19. #define sfi(n) scanf("%d", &n)
  20. #define pfi(n) printf("%d\n", n)
  21. #define sfi2(n, m) scanf("%d%d", &n, &m)
  22. #define pfi2(n, m) printf("%d %d\n", n, m)
  23. #define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
  24. #define MAXN 105
  25. const int INF = 0x3f3f3f3f;
  26. int mp[MAXN][MAXN];
  27. int tot;
  28. int main()
  29. {
  30. int c, p, w, x, y, px, py;
  31. sfi(c);
  32. while(c--)
  33. {
  34. sfi2(y, x);
  35. y++, x++;
  36. repu(i, , y) repu(j, , y) mp[i][j] = ;
  37. sfi(p);
  38. repu(i, , p)
  39. {
  40. sfi2(px, py);
  41. mp[px][py] = ;
  42. }
  43.  
  44. sfi(w);
  45. repu(i, , w)
  46. {
  47. sfi2(px, py);
  48. mp[px][py] = ;
  49. }
  50. tot = ;
  51. int t1, t2;
  52. repu(i, , y) repu(j, , x)
  53. if(mp[i][j] == )
  54. {
  55. tot++;
  56. t1 = t2 = ;
  57. repu(q, i + , y)
  58. if(mp[q][j] == ) t1++;
  59. else if(mp[q][j] == ) break;
  60. repu(q, j + , x)
  61. if(mp[i][q] == ) t2++;
  62. else if(mp[i][q] == ) break;
  63. if(t1 < t2)
  64. {
  65. repu(q, j, x)
  66. if(mp[i][q] == ) mp[i][q] = ;
  67. else if(mp[i][q] == ) break;
  68. }
  69. else
  70. {
  71. repu(q, i, y)
  72. if(mp[q][j] == ) mp[q][j] = ;
  73. else if(mp[q][j] == ) break;
  74. }
  75. }
  76. pfi(tot);
  77. }
  78. return ;
  79. }

uva 12549的更多相关文章

  1. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  2. uva 12549 最大流

    思路:这题的原型题是比较经典的网络流.原型题模型就是把所有的障碍去掉. 有障碍做法还是一样的,只用将每个列和行重新划分,求最大流就行了. #include <cstring> #inclu ...

  3. UVa 12549 机器人警卫(最小点覆盖)

    https://vjudge.net/problem/UVA-12549 题意: 在一个Y行X列的网格里有空地(.),重要位置(*)和障碍物(#),用最少的机器人看守所有重要位置,每个机器人要放在一个 ...

  4. UVA 12549 Sentry Robots (最小点覆盖)

    这道题挺像hdu 5093 Battle ships的,不过那道题是要求最多放置的点数,而这道题是要求最小点覆盖. 顶点覆盖的定义是:在G中任意边至少有一个端点属于顶点集合S. 一个重要的位置有(x, ...

  5. 紫书 习题 11-9 UVa 12549 (二分图最小点覆盖)

    用到了二分图的一些性质, 最大匹配数=最小点覆盖 貌似在白书上有讲 还不是很懂, 自己看着别人的博客用网络流写了一遍 反正以后学白书应该会系统学二分图的,紫书上没讲深. 目前就这样吧. #includ ...

  6. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  7. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  8. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  9. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

随机推荐

  1. 【转】Source Insight的Alt + W键不能使用的解决办法

    转载地址:http://velep.com/archives/607.html 对于Source Insight 3.5,习惯于使用Alt + W组合键并配合数字键来切换文件窗口,带来无比的便利.但是 ...

  2. No row with the given identifier exists:错误另解

    这是一个hibernate常见的问题.搜索出来最多的答案都是如下面这篇文章所述: http://blog.csdn.net/eyejava/article/details/1896492 但我觉得我问 ...

  3. Bootstrap学习(2)--表单

    Bootstrap里的role属性,增强标签的语义化,提高识别力,  如:<form role="form"> input.select.textarea等元素,在Bo ...

  4. TopCoder kawigiEdit插件配置

    kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...

  5. 立即执行函数: (function(){...})() 与 (function(){...}()) 有什么区别?

    没有区别. function foo() {...} // 这是定义,Declaration:定义只是让解释器知道其存在,但是不会运行. foo(); // 这是语句,Statement:解释器遇到语 ...

  6. sendEmail报错:at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm

    sendEmail发送邮件是出现以下报错: *******************************************************************  Using the ...

  7. javascript 变量提前

    1. 未声明变量时,结果是我们预期的结果,报错这个变量没有定义. (function() { // 报错:variable is not defined console.log(variable); ...

  8. iOS解决NSData转NSString后字符为空

    iOS中,将NSData转NSString的一般方法为[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];但是当dat ...

  9. Javascript学习笔记:3种递归函数中调用自身的写法

    ①一般的通过名字调用自身 function sum(num){ if(num<=1){ return 1; }else{ return num+sum(num-1); } } console.l ...

  10. 深入理解IOC模式及Unity框架

    研究了下,有几篇博客确实已经说得很清楚了 1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html  这篇博客是通过一个 ...