zoukankan      html  css  js  c++  java
  • uva 12549

    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

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

    #include <cstdio>
    #include <iostream>
    #include <sstream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <stack>
    #include <algorithm>
    using namespace std;
    #define ll long long
    #define _cle(m, a) memset(m, a, sizeof(m))
    #define repu(i, a, b) for(int i = a; i < b; i++)
    #define repd(i, a, b) for(int i = b; i >= a; i--)
    #define sfi(n) scanf("%d", &n)
    #define pfi(n) printf("%d
    ", n)
    #define sfi2(n, m) scanf("%d%d", &n, &m)
    #define pfi2(n, m) printf("%d %d
    ", n, m)
    #define pfi3(a, b, c) printf("%d %d %d
    ", a, b, c)
    #define MAXN 105
    const int INF = 0x3f3f3f3f;
    int mp[MAXN][MAXN];
    int tot;
    int main()
    {
        int c, p, w, x, y, px, py;
        sfi(c);
        while(c--)
        {
            sfi2(y, x);
            y++, x++;
            repu(i, 1, y) repu(j, 1, y) mp[i][j] = 1;
            sfi(p);
            repu(i, 0, p)
            {
                sfi2(px, py);
                mp[px][py] = 2;
            }
    
            sfi(w);
            repu(i, 0, w)
            {
                sfi2(px, py);
                mp[px][py] = 3;
            }
            tot = 0;
            int t1, t2;
            repu(i, 1, y) repu(j, 1, x)
            if(mp[i][j] == 2)
            {
                tot++;
                t1 = t2 = 0;
                repu(q, i + 1, y)
                if(mp[q][j] == 2) t1++;
                else if(mp[q][j] == 3) break;
                repu(q, j + 1, x)
                if(mp[i][q] == 2) t2++;
                else if(mp[i][q] == 3) break;
                if(t1 < t2)
                {
                    repu(q, j, x)
                    if(mp[i][q] == 2) mp[i][q] = 1;
                    else if(mp[i][q] == 3) break;
                }
                else
                {
                    repu(q, i, y)
                    if(mp[q][j] == 2) mp[q][j] = 1;
                    else if(mp[q][j] == 3) break;
                }
            }
            pfi(tot);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    遭遇:“传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确” 错误
    JS控制form表单action去向
    easyui form 提交问题,纠结了很久,有点诡异
    easyui的tab加载页面中的form重复提交
    AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
    $.AJAX参数提交及后台获取方式
    多条件判断语句case
    条件判断语句if
    条件测试和捕获信号
    向脚本传递参数
  • 原文地址:https://www.cnblogs.com/sunus/p/4839564.html
Copyright © 2011-2022 走看看