[TOJ 1029] Robbery
来源:互联网 发布:开源企业软件 编辑:程序博客网 时间:2024/06/05 06:05
But this time, he has had enough! Inspector Robstop decides to analyze how the robber could have escaped. To do that, he asks you to write a program which takes all the information the inspector could get about the robber in order to find out where the robber has been at which time.
Coincidentally, the city in which the bank was robbed has a rectangular shape. The roads leaving the city are blocked for a certain period of time t, and during that time, several observations of the form "The robber isn't in the rectangle Ri at time ti" are reported. Assuming that the robber can move at most one unit per time step, your program must try to find the exact position of the robber at each time step.
Input
The input contains the description of several robberies. The first line of each description consists of three numbers W, H, t (1 ≤ W,H,t ≤ 100) where W is the width, H the height of the city and t is the time during which the city is locked.
The next contains a single integer n (0 ≤ n ≤ 100), the number of messages the inspector received. The next n lines (one for each of the messages) consist of five integers ti, Li, Ti, Ri, Bi each. The integer ti is the time at which the observation has been made (1 ≤ ti ≤ t), and Li, Ti, Ri, Bi are the left, top, right and bottom respectively of the (rectangular) area which has been observed. (1 ≤ Li ≤ Ri ≤ W, 1 ≤ Ti ≤ Bi ≤ H; the point (1, 1) is the upper left hand corner, and (W, H) is the lower right hand corner of the city.) The messages mean that the robber was not in the given rectangle at time ti.
The input is terminated by a test case starting with W = H = t = 0. This case should not be processed.
Output
For each robbery, first output the line "Robbery #k:", where k is the number of the robbery. Then, there are three possibilities:
If it is impossible that the robber is still in the city considering the messages, output the line "The robber has escaped."
In all other cases, assume that the robber really is in the city. Output one line of the form "Time steps: The robber has been at x,y." for each time step, in which the exact location can be deduced. (x and y are the column resp. row of the robber in time step.) Output these lines ordered by time .
If nothing can be deduced, output the line "Nothing known." and hope that the inspector will not get even more angry.
Output a blank line after each processed case.
Sample Input
4 4 541 1 1 4 31 1 1 3 44 1 1 3 44 4 2 4 410 10 312 1 1 10 100 0 0
Sample Output
Robbery #1:Time step 1: The robber has been at 4,4.Time step 2: The robber has been at 4,3.Time step 3: The robber has been at 4,2.Time step 4: The robber has been at 4,1.Robbery #2:The robber has escaped.直接搜索出每一时刻的情况即可。
#include<iostream>#include<cstring>using namespace std;bool vis[110][110][110];int dp[110][110][110];int dir[5][2]={0,0,1,0,0,1,0,-1,-1,0};int W,H,T,tim,li,ti,ri,bi;int n,xx,yy;int dfs(int x,int y,int t){ if(dp[t][x][y]!=-1) return dp[t][x][y]; if(t==T) return dp[t][x][y]=1; for(int i=0;i<5;i++) { xx=x+dir[i][0]; yy=y+dir[i][1]; if(vis[t+1][xx][yy]&&dfs(xx,yy,t+1)==1) dp[t][x][y]=1; } if(dp[t][x][y]==-1) dp[t][x][y]=0; return dp[t][x][y];}int main(){ int cas=1; while(cin>>W>>H>>T&&(W+H+T)) { memset(vis,0,sizeof(vis)); memset(dp,-1,sizeof(dp)); for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) for(int k=0;k<=T+1;k++) vis[k][i][j]=1; cin>>n; while(n--) { cin>>tim>>li>>ti>>ri>>bi; for(int i=ti;i<=bi;i++) for(int j=li;j<=ri;j++) vis[tim][i][j]=0; } cout<<"Robbery #"<<cas++<<":"<<endl; int ans=0; for(int i=1;i<=H;i++) { for(int j=1;j<=W;j++) { if(vis[1][i][j]) { if(dfs(i,j,1)==1) ans++; } } } if(ans==0) { cout<<"The robber has escaped."<<endl; } else { bool is=1; for(int i=1;i<=T;i++) { int tmp=0; for(int j=1;j<=H;j++) { for(int k=1;k<=W;k++) { if(dp[i][j][k]==1) { //cout<<i<<" "<<j<<" "<<k<<endl; tmp++; xx=j; yy=k; } } } if(tmp==1) { cout<<"Time step "<<i<<": The robber has been at "<<yy<<","<<xx<<"."<<endl; is=0; } } if(is) cout<<"Nothing known."<<endl; } cout<<endl; }}
- [TOJ 1029] Robbery
- The Robbery
- zoj 1144 Robbery
- poj 1104 Robbery
- [ZOJ1144][POJ1104] Robbery
- zoj 3511 Cake Robbery
- zoj 3511 Cake Robbery
- zoj 3511 Cake Robbery
- ZOJ3511 Cake Robbery,暴力
- poj3900The Robbery(贪心+dfs)
- POJ 3900 The Robbery
- 搜索 HOJ 1136 Robbery
- UVA 707 - Robbery
- CodeForce 89A.Robbery
- Just another Robbery LightOJ
- LightOJ1079-Just another Robbery
- POJ 1104 Robbery 笔记
- codeforce A. Bank Robbery
- LVS快速搭建教程
- Linux内核配置(转)
- 给中国学生的第五封信:你有选择的权利(下)
- SQLserver中用convert函数转换日期格式
- Linux等待队列wait_queue_head_t和wait_queue_t
- [TOJ 1029] Robbery
- git_学习笔记
- MEDICAL EQUIPMENT OPENCART 自适应主题模板 ABC-0148
- 浅谈 磁盘调度算法
- HDU 2680 Choose the best route <迪杰斯特拉算法>
- lettcode-102:Binary Tree Level Order Traversal (Java)
- cocos2d-x开发日志08 —— 绘图工具
- ffmpeg文档5_同步视频
- poj 1113(凸包)