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. ASP.NET MVC学习---(三)EF简单增删改查

    那么现在我们已经大概从本质上了解了ef 巴拉巴拉说了一大堆之后 总算要进入ef的正题了 总在口头说也太不行了是吧~ 没错,现在要用ef进行一些实际的操作 做什么呢? 就做一个入门级的增删改查操作吧 废 ...

  2. 配置Linux实现静态路由

    配置Linux实现静态路由 背景和原理 路由器的功能是实现一个网段到另一个网段之间的通信,路由分为静态路由.动态路由. 默认路由和直连路由.静态路由是手工指定的,使用静态路由的好处是网络安全保密性高. ...

  3. 【共享单车】—— React后台管理系统开发手记:Redux集成开发

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  4. 时间操作(JavaScript版)—最简单比較两个时间格式数据的大小

    呵呵呵,在软件研发过程中假设遇到要比較两个时间的大小.你会怎么做.嗯嗯嗯,非常直观的做法就是把"-"去掉,再比較大小,真的有必要吗?看以下最简单的时间比較方式: <!DOCT ...

  5. Poj 4227 反正切函数的应用

    Description 反正切函数可展开成无穷级数,有例如以下公式 (当中0 <= x <= 1) 公式(1) 使用反正切函数计算PI是一种经常使用的方法.比如,最简单的计算PI的方法: ...

  6. Linux非阻塞IO(三)非阻塞IO中缓冲区Buffer的实现

    本文我们来实现回射服务器的Buffer.   Buffer的实现   上节提到了非阻塞IO必须具备Buffer.再次将Buffer的设计描述一下: 这里必须补充一点,writeIndex指向空闲空间的 ...

  7. Windows web服务器搭建---阿里云

      前提步骤: 1)申请域名---- 阿里云.花生壳.万维网等等. 2)云主机购买-----阿里云.腾讯云.京东云等等. 3)网站备案,此步骤最长. 4)建立网站 5)部署网站 下面主要介绍如何部署网 ...

  8. Hive命令行经常使用操作(数据库操作,表操作)

    数据库操作 查看全部的数据库 hive> show databases ; 使用数据库default hive> use default; 查看数据库信息 hive > descri ...

  9. window.name实现跨域数据传输

    偶然间碰到个问题,通过JS给window.name赋值数组情况下,在firefox与chrome下会转换为字符串类型,在IE11下则显示正常.不说了,上图(firefox下): 代码: <scr ...

  10. 【SpringMVC学习03】SpringMVC中注解和非注解方式下的映射器和适配器总结

    从上一篇的springmvc入门中已经看到,springmvc.xml中的配置了映射器和适配器,是使用非注解的方式来配置的,这是非注解方式的一种,这里再复习一下: 1. 非注解方式 1.1 处理器适配 ...