Question link:
Poj: http://poj.org/problem? Id = 1071
HDU: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1364
Zoj: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 19
Description
Tom the robocat is presented in a robotics exhibition for an enthusiastic audience of youngsters, placed around an M * n field. tom which is turned off initially is placed in some arbitrary point in the field by a volunteer from the audience. at time zero of the show, Tom is turned on by a remote control. poor Tom is shown a holographic injection sion of Jerry in a short distance such that a direct path between them is either vertical or horizontal. there may be obstacles in the field, but the specified sion is always placed such that in the direct path between Tom and the specified Sion, there wocould be no obstacles. tom tries to reach Jerry, but as soon as he gets there, the impact changes its place and the chase goes on. let's call each chase in one direction (Up, down, left, and right), a chase trip. each trip starts from where the last partition SiON was deemed and ends where the next partition is deemed out. after a number of Chase trips, the holographic combination sion no more shows up, and poor Tom wonders what to do next. at this time, he is signaled that for sure, if he returns to where he started the chase, a real Jerry is sleeping and he can catch it.
To simplify the problem, we can consider the field as a grid of squares. some of the squares are occupied with obstacles. at any instant, Tom is in some unoccupied square of the grid and so is Jerry, such that the direct path between them is either horizontal or vertical. it's assumed that each time Tom is shown an aggregation Sion; he can reach it by moving only in one of the four directions ctions, without bumping into an obstacle. tom moves into an adjacent square of the grid by taking one and only one step.
The problem is that Tom's logging mechanism is a bit fuzzy, thus the number of steps he has taken in each chase trip is logged as an interval of integers, e.g. 2 to 5 steps to the left. now is your turn to send a program to Tom's memory to help him go back. but to keep your task in this contest, your program shocould only count all possible places that he might have started the chase from.
Input
The first line of the input contains a single integer T (1 <= T <= 10), the number of test cases, followed by the input data for each test case. the first line of each test case contains two integers m and n, which are the number of rows and columns of the grid respectively (1 <= m, n <= 100 ). next, there are m lines, each containing N integers which are either 0 or 1, indicating whether the corresponding cell of the grid is empty (0) or occupied by an obstacle (1 ). after description of the field, there is a sequence of lines, each corresponding to a chase trip of Tom (in order ). each line contains two positive integers which together specify the range of steps Tom has taken (aggressive), followed by a single upper-case character indicating the direction of the chase trip, which is one of the four cases of R (for right), L (for left), u (for UP), and D (for down ). (Note that these directions are relative to the field and are not directions to which Tom turns ). this part of the test case is terminated by a line containing exactly two zeros.
Output
For each test case, there shoshould be a single line, containing an integer indicating the number of cells that Tom might have started the chase from.
Sample Input
26 60 0 0 0 0 00 0 0 1 1 00 1 0 0 0 00 0 0 1 0 00 0 0 1 0 10 0 0 0 0 11 2 R1 2 D1 1 R0 03 40 0 0 00 0 0 00 0 0 01 2 R3 7 U0 0
Sample output
100
Source
Tehr 2001
Question:
A map of M * n is given, and a series of robot actions are given. The robot can start from any point and calculate the number of possible start points of the robot;
Each action consists of a range and a letter. A letter indicates the robot's direction and a range indicates the step.
The Code is as follows:
# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> using namespace STD; typedef struct {int L, R; char dir;} node; node op [100017]; int Mapp [117] [117]; int n, m; int flag = 0; int step; int movee (Int & X, Int & Y, char DIR) {If (DIR = 'U') {If (x-1> = 0 & Mapp [x-1] [Y] = 0) {X --; return 1;} return 0;} else if (DIR = 'D ') {If (x + 1 <M & Mapp [x + 1] [Y] = 0) {x ++; return 1;} return 0 ;} Else if (DIR = 'l') {If (Y-1> = 0 & Mapp [x] [Y-1] = 0) {y --; return 1 ;} return 0;} else if (DIR = 'R') {If (Y + 1 <n & Mapp [x] [Y + 1] = 0) {Y ++; return 1 ;}return 0 ;}} void DFS (int x, int y, int K) {If (MAPP [x] [Y] = 1) return; // the start position cannot be 1; if (x <0 | x> = M | Y <0 | Y> = N) return; // not in the graph; If (k = step) {flag = 1; return;} int I; for (I = 1; I <op [K]. l; I ++) {If (! Movee (X, Y, OP [K]. DIR) return;} For (; I <= op [K]. r; I ++) {If (movee (X, Y, OP [K]. DIR) {DFS (X, Y, k + 1); If (FLAG) return;} else break;} return ;} int main () {int T; scanf ("% d", & T); int A, B; char tt; while (t --) {scanf ("% d", & M, & N); For (INT I = 0; I <m; I ++) {for (Int J = 0; j <n; j ++) {scanf ("% d", & Mapp [I] [J]) ;}} step = 0; while (1) {scanf ("% d ", & A, & B); if (a = 0 & B = 0) break; getchar (); scanf ("% C", & TT ); OP [STEP]. L = A; OP [STEP]. R = B; OP [step ++]. dir = tt;} int ans = 0; For (INT I = 0; I <m; I ++) {for (Int J = 0; j <N; j ++) {flag = 0; DFS (I, j, 0); If (FLAG) ans + = 1 ;}} printf ("% d \ n ", ans);} return 0 ;}
Poj 1071 & HDU 1364 & zoj 1019 aggressive sive Chase (DFS)