uva707 - Robbery 记忆化搜索

poj3900The Robbery(贪心+dfs) The Robbery Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1523   Accepted: 140 Description In the downtown of Bucharest there is a very big bank with a v 阅读详情

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 \le W, H, t \le 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 \le n \le 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 tiis the time at which the observation has been made ( $1 \le t_i \le t$), and Li, Ti, Ri, Bi are the left, top, right and bottom respectively of the (rectangular) area which has been observed. ($1 \le L_i \le R_i \le W, 1 \le T_i \le B_i \le 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 $\tau$: 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 $\tau$.) Output these lines ordered by time $\tau$.

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个信息,每个信息告诉你左上角和右下角坐标围成的区域在某一时间没有抢劫犯。如果抢劫犯逃走了输出The robber has escaped.,否则输出能确定抢劫犯位置的时间和坐标,如果一个时间都不能确定输出Nothing known.。

  记忆化搜索,dp[t][x][y]表示时间t坐标x,y能否确定小偷存在,0表示不存在,1表示不确定。最后搜完以后对于某个t,如果只有一个1,那确定肯定在那一点。关键是搜索,最开始把不能的地方dp都置0,只要搜DFS(1,i,j)就行了,因为有些点根本就不可达。还有一点是他可以不动,写四个方向的写惯了,还把这里漏了=。=

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
using namespace std;

typedef pair<int,int> pii;

const int MAXN=110;
const int MAXM=MAXN*MAXN/2;
const int MAXNODE=32;
const int LOGMAXN=50;
const int INF=0x3f3f3f3f;

int move[5][2]={0,0,-1,0,0,-1,0,1,1,0};
int W,H,T,N;
int dp[MAXN][MAXN][MAXN],no[MAXN][MAXN][MAXN];

int DFS(int t,int x,int y){
    int& ans=dp[t][x][y];
    if(ans!=-1) return ans;
    if(t>=T) return ans=1;
    ans=0;
    for(int i=0;i<5;i++){
        int X=x+move[i][0],Y=y+move[i][1];
        if(X>0&&X<=W&&Y>0&&Y<=H) if(DFS(t+1,X,Y)){
            ans=1;
        }
    }
    return ans;
}

int main(){
    freopen("in.txt","r",stdin);
    int cas=0;
    while(scanf("%d%d%d",&W,&H,&T)!=EOF&&(W||H||T)){
        scanf("%d",&N);
        int t,x1,y1,x2,y2;
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<N;i++){
            scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);
            for(int j=x1;j<=x2;j++)
                for(int k=y1;k<=y2;k++) dp[t][j][k]=0;
        }
        for(int i=1;i<=W;i++)
            for(int j=1;j<=H;j++) DFS(1,i,j);
        printf("Robbery #%d:\n",++cas);
        int flag=0;
        for(int i=1;i<=T;i++){
            int cnt=0,x,y;
            for(int j=1;j<=W;j++)
                for(int k=1;k<=H;k++) if(dp[i][j][k]==1){
                    cnt++;
                    x=j;
                    y=k;
                }
            if(cnt==0){
                flag=2;
                break;
            }
            if(cnt==1){
                flag=1;
                printf("Time step %d: The robber has been at %d,%d.\n",i,x,y);
            }
        }
        if(!flag) printf("Nothing known.\n");
        else if(flag==2) printf("The robber has escaped.\n");
        puts("");
    }
    return 0;
}


SAP ABAP SM50 的另类用途 - ABAP 工作进程对数据库表读取操作的检测 今天是2020年五一国际劳动节,Jerry祝大家劳动节快乐。 虽然五一国际劳动节来源于一百多年前国外无产阶级的一次大罢工,但由于国情原因,国内很多行业的从业人员,好像天生就是劳碌命。比如程序员行业。 2014年五一劳动节,我在和一个不是总能重现的SAP CRM incident做斗争。详情参考Jerry之前的文章记一次SAP开发工程师给微软Azure报incident的体验. 当时处理完这个复杂... 阅读详情

相关推荐

大模型运维实战:从GPU选型到推理服务稳定落地

大模型服务进入生产环境后,运维对象从传统进程转向GPU显存、KV Cache、推理吞吐等动态资源。显存利用率、首token延迟、并发队列深度等指标,直接影响模型服务的质量与成本。理解推理框架的内存分配机制、掌握监控告警与自动化扩容手段,是保障服务稳定的关键。这类能力广泛应用于企业私有化部署、智能客服、知识库问答等场景,帮助运维团队从被动救火转向主动容量规划与性能调优。本文围绕大模型运维的完整路线,梳理从硬件选型、推理部署到监控排障的实战经验,并算清一份真实项目的长期成本账。

weixin_29054245的博客 238

搜索 HOJ 1136 Robbery

Robbery My Tags   (Edit)   Source : ACM ICPC Mid-Central European 1999   Time limit : 3 sec   Memory limit : 32 M Submitted : 16, A

We Can 789

Keil5编译报错:ARM Compiler Version 5缺失的完整解决方案

本文提供了Keil5编译报错“ARM Compiler Version 5缺失”的完整解决方案。详细介绍了手动安装ARM Compiler Version 5的步骤,包括下载安装包、配置编译器路径及常见问题排查,帮助开发者快速恢复老项目的编译环境。

bb456的博客 945

LightOJ-1079 Just another Robbery

用概率背包dp,d[i]表示拿到 i 金钱最小被抓概率 初始化d[0]=0.0,然后把每个银行过一遍,每次更新d数组 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #include&lt;cmath&gt; using namespace st...

wl16wzl的博客 192

Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包

联网情况下在命令终端CMD中输入“pip install numpy”即可自动安装,pandas和matplotlib同理一样方法进行自动安装。 工作的电脑不能上外网,所以不能通过直接输入pip命令来安装。 环境:电脑上已经安装了Python(没有安装的请参考其他教程)。 Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包的步骤如下: ...

dayou7738的博客 4940

从模型车到真实路口:基于YOLOv5-Lite与SORT的轻量化车流量检测系统实战

本文详细阐述了如何将基于YOLOv5-Lite与SORT的轻量化车流量检测系统从毕业设计原型部署到真实路口。文章聚焦于解决在嵌入式平台(如树莓派)上实现实时、稳定检测的工程挑战,涵盖数据采集、模型微调、系统集成及动态信号灯策略,为智能交通灯系统提供了实用的轻量化解决方案。

weixin_29179311的博客 125

Robbery(记忆化搜索)

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

weixin_34064653的博客 387

从理论到代码:蒙特卡洛法在光学散射模拟中的应用全解析(Matlab 2014a版)

本文详细解析了蒙特卡洛法在光学散射模拟中的应用,从数学原理到Matlab 2014a实现。通过模拟光子随机游走过程,精确描述光在浑浊介质中的传输特性,提供完整的源码实现和性能优化技巧,适用于生物医学光学、大气遥感等领域。

rum55的博客 626

UVA 707 - Robbery【记忆化搜索】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=599&problem=648&mosmsg=Submission+received+with+ID+14106133题意: 在一个w * h的图上,t个时刻,然后给你一些信息,知道某些时刻没

mfcheer 836

深度剖析XY2-100与SL2-100协议:解锁激光打标核心技术密码

XY2-100和SL2-100是激光打标领域的两种核心控制协议。XY2-100协议采用串行通信,指令集简单,适合常规打标任务,具有成本优势;SL2-100协议支持更高速率(1Mbps以上),具备曲线插补等高级指令,在精密加工领域表现突出。两者的主要差异体现在数据传输(帧结构、速率)、指令集(功能、数量)、参数调节(范围、精度)和错误处理机制等方面。实际应用中,XY2-100适合简单图形的大批量生产,SL2-100更胜任复杂曲面的高精度加工。选择时需综合考虑打标需求、设备兼容性和成本因素,未来两种协议将持续优

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 957

【气候极端指数】MATLAB计算各种气候极端指数

简介各类气候极端指数,及其MATLAB计算代码

WW、forever的博客 4917

uva 707 - Robbery(记忆化搜索)

题目连接:uva 707 - Robbery dp[x][y][t]表示在t时刻x,y时有没有可能存在盗贼,整个时刻只有一个点可以时就可以确定,没有点可能时就是逃脱。 #include #include #include #include #include using namespace std; typedef pair pii; const int maxn =

不慌不忙、不急不躁 745

深入理解JVM虚拟机第一篇:Java跨平台和字节码以及多语言混合编程

本位描述了Java的跨平台和JVM的跨平台的作用,Java语言的字节码的概念多语言混合编程应用到JVM虚拟机以及Java发展的重大事件。

七叔的博客 1万+

UVA 707 - Robbery(记忆化搜索)

UVA 707 - Robbery 题目链接 题意:在一个w * h的图上,t个时刻,然后知道一些信息,每个时刻没有小偷的矩阵位置,问哪些时刻可以唯一确定小偷位置,和确定小偷是否已经逃走,如果没逃走,但是也没有时刻可以可以确定小偷位置,就是不知到 思路:记忆化搜索,dp[x][y][ti]表示在x,y位置,ti时刻时候,小偷是否可能出现在这个位置,1表示有可能,0表示没可能,由于

Remilia's 1345

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

UVA707Robbery(记忆化搜索)

题意:、 一个n*m的城市,有小偷会偷银行,小偷偷东西t分钟后,城市会被全部封锁,然后会有q次排查,每次排查的范围是一个矩形,给出左上角坐标(a,b)和右下角坐标(c,d),格式为t a,b,c,d,表示这个范围该时间小偷不在,输出所有小偷可能在的位置和时间。小偷在此过程中每秒最多可以移动一个单位的距离 分析: 一共有三种情况,确定小偷所在的位置和时间,小偷逃离城市,一无所获,要描述一个状态

Rain 432

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

uva 707 Robbery(记忆化搜索)

题意:一个n*m的城市,有小偷会偷银行,小偷偷东西t分钟后,城市会被全部封锁,然后会有q次排查,每次排查的范围是一个矩形,给出左上角坐标(a,b)和右下角坐标(c,d),格式为t a,b,c,d,表示这个范围该时间小偷不再,输出所有小偷可能在的位置和时间 分析:一共有三种情况,确定小偷所在的位置和时间,小偷逃离城市,一无所获,要描述一个状态,至少要有三个量,(x,y,t),因为不知道小...

weixin_30687587的博客 109

UVA 707 - Robbery(内存搜索)

UVA 707 - Robbery 题目链接 题意:在一个w * h的图上。t个时刻,然后知道一些信息,每一个时刻没有小偷的矩阵位置,问哪些时刻能够唯一确定小偷位置。和确定小偷是否已经逃走,假设没逃走。可是也没有时刻能够能够确定小偷位置,就是不知到 思路:记忆化搜索。dp[x][y][ti]表示在x。y位置。ti时刻时候,小偷是否可能出如今这个位置,1表示有可能。0表...

weixin_30278237的博客 88

UVA 707 - Robbery

搜啊搜~~~~~~~ 1.用记忆化搜索 来搜答案,否则搜不完~ 2.题目理解起来有困难....sad 讲:如果最后没有找到任何时间任何地点可能有贼,说明他跑掉了        除了上面这种情况,如果在所有时间里都同时存在多于一个点可能有贼,则Nothing known 除了上面两种情况,输出能确定贼的时间和该时间贼的地点 #include #include #include #incl

GejinZ 668

LightOJ 1163 - Bank Robbery (思维方程式求解)

1163 - Bank Robbery   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In one very cold morning, Mark decides to rob a b

滴水穿石,慢慢积累,总会有成果 1055

[TOJ 1029] 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 pow

menguands的专栏 414

Dinic+当前弧优化

Dinic算法是不停用BFS构造层次图,然后

7141

Dijkstra 求最短路 最大流

原来Dijkstra算法不光只能求最短路问题,还能求最大流问题~~~求最短路 最大流" title="Dijkstra 求最短路 最大流"> 最短路问题时,Dijkstra算法的基本思想:   邻接矩阵w[x][y]保存x和y间的距离(别的设为INF,表示不连通,设为-1也行,后来更新加一个if(w[x][y]>=0)),数组d保存通过已经确定的点从起点到每个点的最短路。初始化d[0]=0,

1847

网络流 最大流 Edmonds-Karp算法

Edmonds-Karp算法,复杂度O(VE^2)。思想就是找增广路,不断增加流量。在残量(每条边上流量和容量的差)图上找一条每个边权值都为正的路(可以通过BFS,比DFS效率高),这些边权值里的最小值就是这条路可以增加的流量,然后在这条路径上更新流量。再重复找这样的路更新流量,直到找不到这样的路了就说明流量不能再增加了,当前的流就已经是最大流。   同时最大流也是最小割(权值和最小的割集)。设

1842

Bellman_Ford和Spfa两种方法判断负环

Bellman_Ford是通过N-1次循环求出每个点到原点的最短路的,每次循环遍历所有的边,如果能更新就更新。前面说过为什么N-1次就行(若一个点到起点的最短路需要经过N个点,包括他自己,那么第N次循环就能确定他的最短路)。   最短路一定是不含环的,如果存在负环就根本不存在最短路了。所以这个方法可以用来判断是否有负环,如果循环了N-1次后还能进行松弛操作,说明有负环。Bellman_Ford的

1712

hdu5294 Tricks Device 最短路+最小割 多校联合第一场

Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 66    Accepted Submission(s): 14 Problem Description Innocent Wu follows

1563
上一篇: uva10441 - Catenyms 欧拉通路
下一篇: poj2449 Remmarguts' Date 第K短路 A*
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值