Robbery

Inspector Robstop is very angry. Last night, a bank has been robbed and the robber has not been caught. And this happened already for the third time this year, even though he did everything in his power to stop the robber: as quickly as possible, all roads leading out of the city were blocked, making it impossible for the robber to escape. Then, the inspector asked all the people in the city to watch out for the robber, but the only messages he got were of the form “We don’t see him.” 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 file 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 step τ: 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 5

4

1 1 1 4 3

1 1 1 3 4

4 1 1 3 4

4 4 2 4 4

10 10 3

1

2 1 1 10 10

0 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.

//题意看了好久好久才明白,第一行,代表城市的长 W ,宽 H ,然后是 小偷逗留的时间 T

第二行一个整数 n 代表警察搜查的次数

然后 n 行,意思是,时间 t 时,搜查的矩形范围的左上角坐标,和右下角坐标,代表小偷在 t 时刻不在这个范围内

输出的是有关小偷的各个时刻在什么位置的线索,能确定就输出,不能确定就不要输出,没有任何线索输出 Nothing known

如果小偷不可能在城市,输出 The robber has escaped.

DFS搜索,难得是读题啊。。。虽然我看了题解,,,地图要用一个三维数组,不但要记录位置,还要记录时间,

还要记录这个时间,这个位置的可达状态,0表不可达,1表可达,-1代表不确定,然后应该没啥难的了。。。

10ms

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std; int W,H,T,q,ans;
int Map[][][];// (x,y) 时间z
struct Node
{
int x,y;
Node(int a,int b):x(a),y(b)
{}
};
vector<Node> G[]; int dx[]={, ,,-,};
int dy[]={,-,, ,};
int dfs(int x,int y,int tt)
{ if (Map[x][y][tt]!=-)//如果这个状态的情况已经确定了
return Map[x][y][tt];
if (tt==T)//到最后封锁时间,说明这个状态可以
{
ans++;
Map[x][y][tt]=;
G[tt].push_back(Node(x,y));
return ;
}
Map[x][y][tt]=;
for (int i=;i<;i++)
{
int tx=x+dx[i];
int ty=y+dy[i];
if (tx>=&&tx<=W&&ty>=&&ty<=H)
{
if (dfs(tx,ty,tt+)==)//如果接下来的状态可以到,说明自己也可以到
Map[x][y][tt]=;
}
}
if (Map[x][y][tt]==)
{
G[tt].push_back(Node(x,y));
}
return Map[x][y][tt];
} int main()
{
int cas=;
while(scanf("%d%d%d",&W,&H,&T)&&W+H+T)
{
memset(Map,-,sizeof(Map));
scanf("%d",&q);
for (int i=;i<=q;i++)
{
int t,lx,ly,rx,ry;
scanf("%d%d%d%d%d",&t,&lx,&ly,&rx,&ry);
for (int j=lx;j<=rx;j++)
for (int k=ly;k<=ry;k++)
Map[j][k][t]=;
}
for (int i=;i<=T;i++) G[i].clear();
ans=;
for (int i=;i<=W;i++)
{
for (int j=;j<=H;j++)
if (Map[i][j][]==-)
{
dfs(i,j,);
}
}
printf("Robbery #%d:\n",cas++);
if (ans==)
printf("The robber has escaped.\n");
else
{
int res=;
for (int i=;i<=T;i++)
if (G[i].size()==)
{
res++;
printf("Time step %d: The robber has been at %d,%d.\n",i,G[i][].x,G[i][].y);
}
if (res==)
printf("Nothing known.\n");
}
printf("\n");
}
return ;
}

Robbery(记忆化搜索)的更多相关文章

  1. uva 707(记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21261 思路:此题需要记忆化搜索,dp[x][y][t]表示当前状 ...

  2. [ACM_动态规划] 数字三角形(数塔)_递推_记忆化搜索

    1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> ...

  3. 【BZOJ-3895】取石子 记忆化搜索 + 博弈

    3895: 取石子 Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 263  Solved: 127[Submit][Status][Discuss] D ...

  4. hdu3555 Bomb (记忆化搜索 数位DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. zoj 3644(dp + 记忆化搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 思路:dp[i][j]表示当前节点在i,分数为j的路径条数,从 ...

  6. loj 1044(dp+记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26764 思路:dp[pos]表示0-pos这段字符串最少分割的回文 ...

  7. DP(记忆化搜索) + AC自动机 LA 4126 Password Suspects

    题目传送门 题意:训练指南P250 分析:DFS记忆化搜索,范围或者说是图是已知的字串构成的自动机图,那么用 | (1 << i)表示包含第i个字串,如果长度为len,且st == (1 ...

  8. HDU1978 记忆化搜索

    How many ways Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. bzoj4562: [Haoi2016]食物链--记忆化搜索

    这道题其实比较水,半个小时AC= =对于我这样的渣渣来说真是极大的鼓舞 题目大意:给出一个有向图,求入度为0的点到出度为0的点一共有多少条路 从入读为零的点进行记忆化搜索,搜到出度为零的点返回1 所有 ...

随机推荐

  1. N++ 道ASP.NET面试题

    InterviewQuestions-ASP.NET N++ 道ASP.NET面试题 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . ...

  2. Shell--变量键盘读取、数组与声明:read,array,declare

    1.read read [-pt] variable -P:后面可以接提示信息 -t:后面可以接等待的秒数,时间到后等待结束 read后面不加任何参数,直接加变量名称,那么就会主动出现一个空白行等待你 ...

  3. 2017.5.16 comparator和comparable的比较及使用

    参考来自: http://blog.csdn.net/lifuxiangcaohui/article/details/41543347 http://www.cnblogs.com/liuyuanyu ...

  4. Nodejs 模拟telnet

    代码下载:https://files.cnblogs.com/files/xiandedanteng/nodejsTelnet.rar 效果: server.js代码: var net=require ...

  5. 简单的图片处理servlet

    好久没写博客了.近期做了一个比較有趣的商城项目,里面的业务还真的非常复杂,好在做了特殊的处理之后商城也能正常的使用了. 可是没中不足的就是图片目录和项目掺杂在一块,实在有些难以维护.之后找了点资料就搞 ...

  6. 第三章,设置button边框(Android)

    这样的方法是通过层叠几个图片实现边框效果. 在res目录下的drawable目录下(没有就新建)建一个xml文件选layer-list. <?xml version="1.0" ...

  7. 开发ionic准备之安卓模拟器设置(2)

    发现这个安卓模拟器设置屏幕还不能太大,太大显示不全,然后整个模拟器不能拖动,所以尽量不要设置太大的分辨率 ,如下即可 如果选安卓4.4然后勾选了其他下面的ok还不能点击的话,这下要去sdk manag ...

  8. APP开发关于缓存

    1 http://www.cnblogs.com/qianxudetianxia/archive/2012/02/20/2112128.html 1.1 http://blog.csdn.net/ln ...

  9. Spring Web Flow 入门demo(三)嵌套流程与业务结合 附源代码

    上篇博客我们说Spring web Flow与业务结合的方式主要有三种,以下我们主要介绍一下第三种的应用方式 3,运行到<action-state> 元素 SpringWeb Flow 中 ...

  10. svn解决冲突和commit

    当使用svn出现 svn: E155015: 提交失败(细节如下):svn: E155015: 提交终止: “/home/test.file” 处于冲突状态 解决办法: svn resolved /h ...