日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > hdu Illusive Chase 1364 dfs

hdu Illusive Chase 1364 dfs

來源:程序員人生   發布時間:2015-03-31 07:55:56 閱讀次數:3395次
Illusive Chase


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 174    Accepted Submission(s): 74




Problem 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 illusion 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 illusion is always placed such that in the direct path between Tom and the illusion, there would be no obstacles. Tom tries to reach Jerry, but as soon as he gets there, the illusion 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 illusion was deemed and ends where the next illusion is deemed out. After a number of chase trips, the holographic illusion 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 illusion; he can reach it by moving only in one of the four directions, 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 ease your task in this contest, your program should only count all possible places that he might have started the chase from.
 


Input
The first line of the input file 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 (inclusive), 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 should be a single line, containing an integer indicating the number of cells that Tom might have started the chase from.
 


Sample Input
2
6 6
0 0 0 0 0 0
0 0 0 1 1 0
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 1 0 1
0 0 0 0 0 1
1 2 R
1 2 D
1 1 R
0 0
3 4
0 0 0 0
0 0 0 0
0 0 0 0
1 2 R
3 7 U
0 0
 


Sample Output
10

0

 


題意:輸入1個地圖,0表示可以走,1表示不能走。接下來再出現0 0  之前,輸入若干個操作。前兩個數字代表走的步數范圍,每次走的步數都可以是在這個范圍里的任意步。最后1個字母代表 走的方向。 輸出有多少個 為0的位置可以作為起始點。起始位置的要求是,有1種的走法,可使其  走完 給的若干個操作后,在走的進程中 不會遇到障礙1 ,并且不會超越地圖范圍。

第2個案例,由于第2個操作 最少向上走3步, 所以肯定超越范圍了。所以沒有點可以做為起始點。


 做法:枚舉所有點,dfs  所有走的步數范圍。 注意 如果步數范圍 在3⑺ 之間,那末 在小于3步的范圍內,不能出現障礙,否者不能走。


#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <stack> #include <queue> #include <vector> #include <deque> #include <set> #include <map> int lim; int mp[150][150]; int n,m; int lr[100017][2]; char ch[100017]; int ok(int x,int y) { if(x<=n&&x>=1&&y>=1&&y<=m) { if(mp[x][y]==0) return 1; } return 0; } int dfs(int x,int y,int nw)//f R (for right), L (for left), U (for up), and D (for down). (N { if(!ok(x,y)) return 0; if(nw==lim) return 1; if(ch[nw]=='R')//nw+1 { for(int i=1;i<lr[nw][0];i++) { if(!ok(x,y+i)) return 0; } for(int i=lr[nw][0];i<=lr[nw][1];i++) { if(!ok(x,y+i)) break; if(dfs(x,y+i,nw+1)) return 1; } } if(ch[nw]=='L')//nw+1 { for(int i=1;i<lr[nw][0];i++) { if(!ok(x,y-i)) return 0; } for(int i=lr[nw][0];i<=lr[nw][1];i++) { if(!ok(x,y-i)) break; if(dfs(x,y-i,nw+1)) return 1; } } if(ch[nw]=='U')//nw+1 { for(int i=1;i<lr[nw][0];i++) { if(!ok(x-i,y)) return 0; } for(int i=lr[nw][0];i<=lr[nw][1];i++) { if(!ok(x-i,y)) break; if(dfs(x-i,y,nw+1)) return 1; } } if(ch[nw]=='D')//nw+1 { for(int i=1;i<lr[nw][0];i++) { if(!ok(x+i,y)) return 0; } for(int i=lr[nw][0];i<=lr[nw][1];i++) { if(!ok(x+i,y)) break; if(dfs(x+i,y,nw+1)) return 1; } } return 0; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&mp[i][j]); int l,r; lim=0; char c; while(scanf("%d%d",&l,&r),l||r) { getchar(); cin>>c; if(l>r) swap(l,r); lr[lim][0]=l; lr[lim][1]=r; ch[lim++]=c; } int ans=0; for(int ii=1;ii<=n;ii++) { for(int j=1;j<=m;j++) { if(ok(ii,j)&&dfs(ii,j,0)) ans++; } } printf("%d ",ans); } return 0; }







生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产精品一区二区6 | 亚洲精品一级 | 亚洲国产精品一区二区第一页 | 久久久成人精品 | 99久久免费看视频 | 色婷婷精品国产一区二区三区 | 国产精品视频在线观看 | 97在线观看视频 | 国产激情在线 | 日韩精品一区二区三区中文在线 | 国产精品久久久久一级毛片 | 日韩在线播放一区 | 欧美黄色免费大片 | 亚洲视频在线观看网址 | 国产精品视频1区2区3区 | 国产真实夫妇6p酒店交换 | 欧美日韩电影一区二区 | 欧美日韩国产中文 | 亚洲精品综合在线 | 国户精品久久久久久久久久久不卡 | 久久久久久一区二区三区四区别墅 | 伊人伊人网 | av片在线观看 | 91久久综合亚洲鲁鲁五月天 | 毛片com| 国产成人精品免费视频大全最热 | 日韩在线精品视频 | 欧美日韩精品一区二区公司 | 韩日三级电影 | 美女国内精品自产拍在线播放 | 蜜桃导航-精品导航 | 中文字幕一区二区在线播放 | 久久最新网址 | 国产在线观看一区二区三区 | 免费一级毛片视频 | 国产乱码精品一区二区三区不卡 | 欧美在线免费观看 | 成人h动漫精品一区二区器材 | 日韩一区二区精品 | 91精品久久久久久久蜜月 | 伊人国产在线观看 |