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. 通过CVE-2017-17215学习路由器漏洞分析,从入坑到放弃

    1.基本信息: 2017/11/27,Check Point 软件技术部门报告了一个华为 HG532 产品的远程命令执行漏洞(CVE-2017-17215),Mirai的升级版变种中已经使用该漏洞.看 ...

  2. Uncaught SyntaxError: Invalid Unicode escape sequence异常处理

    今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...

  3. ES6中的迭代器(Iterator)和生成器(Generator)(一)

    用循环语句迭代数据时,必须要初始化一个变量来记录每一次迭代在数据集合中的位置,而在许多编程语言中,已经开始通过程序化的方式用迭代器对象返回迭代过程中集合的每一个元素 迭代器的使用可以极大地简化数据操作 ...

  4. oracle学习小知识点总结

    登陆数据库:sqlplus "/as sysdba" window身份验证,不需要用户名和密码. 查看数据库状态: select status from v$instance(v$ ...

  5. EJB vs Spring

    转载: Spring 自从2003年发布以来,一直是Java开源框架的奇迹之一.从2000年开始,伴随着B/S架构逐渐引入企业应用软件开发的领域,Java就逐渐成为企业应用开发的主流技术,一直到200 ...

  6. ElasticSearch获取指定Field数据的Java方法

    ElasticSearch(ES)检索后需要结果时,可能通过source接口读出.但是这样的话,返回的结果会很多.在调用search方法时,我们可以添加addfield或addfields方法,仅仅读 ...

  7. Centos 7 搭建OpenStack 私有云——(1)基础环境配置

    1.简介: OpenStack是一个由NASA(美国国家航空航天局)和Rackspace合作研发并发起的,以Apache许可证授权的自由软件和开放源代码项目. OpenStack是一个开源的云计算管理 ...

  8. AI学习笔记

    人人都是产品经理,继续设计课程啦啦啦啦 ADOBE: ps, ai, fl, dw, fw, ae, pr, id   COREL: painter coreldraw   autodesk: 三维: ...

  9. 奥巴马(Obama)获胜演讲全文[中英对照]+高清视频下载

    http://www.amznz.com/obama-speech/如果还有人对美国是否凡事都有可能存疑,还有人怀疑美国奠基者的梦想在我们所处的时代是否依然鲜活,还有人质疑我们的民主制度的力量,那么今 ...

  10. HTTP图解--了解Web及网络基础

    1.网络基础TCP/IP 通常使用的网络是在TCP/IP协议族的基础上运行的,http属于它内部的一个子集. TCP/IP协议族按层次分别分为:应用层.传输层.网络层和数据链路层.分层的好处在于各司其 ...