[UVA][散化&dp] 1092 - Tracking Bio-bots@Morris' Blog|PChome Online 人新台
2013-10-11 08:28:37| 人3,183| 回0 | 上一篇 | 下一篇

[UVA][散化&dp] 1092 - Tracking Bio-bots

0 收藏 0 0 站台

The researchers at International Bio-bot Makers (IBM) have invented a new kind of Bio-bot, a robot with behavior mimicking biological organisms. The development of the new robot is at a primitive stage; they now resemble simple four-wheeled rovers. And like most modern robots, Bio-bots are not very mobile. Their weak motors and limited turning capability put considerable limitations on their movement, even in simple, relatively obstacle-free environments.

Currently the Bio-bots operate in a room which can be described as an m x n grid. A Bio-bot occupies a full square on this grid. The exit is in the northeast corner, and the room slopes down towards it, which means the Bio-bots are only capable of moving north or east at any time. Some squares in the room are also occupied by walls, which completely block the robot. Figure 1, which corresponds to the sample input, shows an example of such a room.

epsfbox{p4787.eps}

Clearly, a Bio-bot located on square A is capable of leaving the room, while one at square B is trapped inside it, no matter what it does. Locations like B are called ``stuck squares." (Walls do not count as stuck squares.) Given the description of a room, your job is to count the total number of stuck squares in the room.

Input 

Input consists of multiple test cases, each describing one room. Each test case begins with a line containing three integers m, n, and w (1$ le$m, n$ le$106, 0$ le$w$ le$1000). These indicate that the room contains m rows, n columns, and w horizontal walls.

Each of the next w lines contains four integers x1, y1, x2, y2, the coordinates of the squares delimiting one wall. All walls are aligned from west to east, so 0$ le$x1$ le$x2 < n and 0$ le$y1 = y2 < m. Walls do not overlap each other. The southwest corner of the room has coordinates (0,0) and the northeast corner has coordinates (n - 1, m - 1).

The last test case is followed by a line containing three zeros.

Output 

For each test case, display one line of output containing the test case number followed by the number of stuck squares in the given oom. Follow the format shown in the sample output.

Sample Input 

8 8 3 1 6 3 6 2 4 2 4 4 2 7 2 0 0 0 

Sample Output 

Case 1: 8 



目描述:

只能往右往上走,求中有多少法抵右上角。

目解法:


首先,先 x, y 散化,用 dp 推回去找到可以抵的。

於不能抵的,散化的果拿出算有多少格子。

#include <stdio.h>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std;
char g[2010][2010], dp[2010][2010];
int lx[4010], rx[4010], ly[4010], ry[4010];
long long x[4010], y[4010];
int main() {
    //freopen("in.txt","r+t",stdin);
    //freopen("out.txt","w+t",stdout);
    int cases = 0;
    int m, n, w;
    int i, j, k, p, q, r;
    while(scanf("%d %d %d", &m, &n, &w) == 3 && n+m) {
        map<int, int> Rx, Ry;
        Rx[0] = 1, Ry[0] = 1;
        Rx[n] = 1, Ry[m] = 1;
        for(i = 0; i < w; i++) {
            scanf("%d %d %d %d", &lx[i], &ly[i], &rx[i], &ry[i]);
            rx[i]++, ry[i]++;
            Rx[lx[i]] = 1, Ry[ly[i]] = 1;
            Rx[rx[i]] = 1, Ry[ry[i]] = 1;
        }
        int sizex = 0, sizey = 0;
        for(map<int, int>::iterator it = Rx.begin();
            it != Rx.end(); it++) {
            it->secOnd= sizex;
            x[sizex++] = it->first;
        }
        for(map<int, int>::iterator it = Ry.begin();
            it != Ry.end(); it++) {
            it->secOnd= sizey;
            y[sizey++] = it->first;
        }
        memset(g, 0, sizeof(g));
        memset(dp, 0, sizeof(dp));
        for(i = 0; i < w; i++) {
            int llx = Rx[lx[i]], rrx = Rx[rx[i]];
            int rry = Ry[ry[i]];
            for(p = llx+1; p <= rrx; p++)
                g[p][rry] = 1;
        }
        dp[sizex-1][sizey-1] = 1;
        long long ret = 0;
        for(i = sizex-1; i > 0; i--) {
            for(j = sizey-1; j > 0; j--) {
                if(g[i][j])
                    continue;
                if(!dp[i][j])
                    ret += (x[i]-x[i-1])*(y[j]-y[j-1]);
                dp[i-1][j] |= dp[i][j];
                dp[i][j-1] |= dp[i][j];
            }
        }
        printf("Case %d: %lld\n", ++cases, ret);
    }
    return 0;
}

台: Morris
人(3,183) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 教育(修、留、研究、教育概) | 人分: UVA |
此分下一篇:[UVA] 1039 - Simplified GSM Network
此分上一篇:[UVA][分&二分] 1280 - Curvy Little Bottles

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86