poj-1104 Robbery
Time Limit: 1000MS | Memory Limit: 32768K | |
Total Submissions: 1249 | Accepted: 504 |
Description
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
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
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.
Source
OJ-ID:
poj-1104
author:
Caution_X
date of submission:
20191024
tags:
模拟
description modelling:
给定一个矩形,现在给定四个点构成一个扫描矩形(扫描矩形在矩形内),表示该扫描矩形范围内没有盗贼,现在给出N个这样的扫描矩形,每个扫描矩形都有对应的时间,表示该扫描发生的时间,现在问能否通过N次扫描判断盗贼的状态(已逃离(离开给定的坐标范围),不确定,或者确定在点(x,y))
major steps to solve it:
vis[t][r][c]=1表示t时刻(r,c)处有盗贼
(1)按照时间正向反向搜索两次,每次扫描的目的在于判断vis[t][r][c]为0的点应不应该是1(因为扫描矩形范围内是1不代表扫描矩形外一定是0,有一些点虽然在扫描矩形外,但它依然必须是1)
(2)完成两次扫描之后遍历时间1~T状态下矩形的点,如果存在某个状态全为1,说明盗贼已经离开了矩形(已逃离),如果某个状态整个矩形只有一点是0,说明该状态下盗贼就在该点。如果所有时间的矩形都扫描过了而且没有得到盗贼的状态,输出不确定时的答案。
正向搜索方式:如果t时刻在(r,c)即vis[t][r][c]=0,那么t-1时刻必然在(r,c)周围(含(r,c))的5个点内,如果这5个点都是1,那么实际上vis[t][r][c]=1。反向搜索类似。
AC code:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int vis[][][];//vis[t][r][c]=1表示第t时刻r行c列没有盗贼
int dir[][]={{,},{,},{,},{,-},{-,}};
int res[][]; //res[i][]表示第i时刻可能的位置
int W,H,T;
bool inrange(int r,int c)
{
return (r>=&&r<=H&&c>=&&c<=W);
}
void change(int r,int c,int t,int pre_t)
{
if(vis[t][r][c]) return;
for(int d=;d<;d++) {
int tmp_r=r+dir[d][];
int tmp_c=c+dir[d][];
if(inrange(tmp_r,tmp_c)&&!vis[pre_t][tmp_r][tmp_c]) return;
}
vis[t][r][c]=;
return;
}
int main()
{
//freopen("input.txt","r",stdin);
int kase=;
while(~scanf("%d%d%d",&W,&H,&T)&&W&&H&&T) {
printf("Robbery #%d:\n",kase++);
memset(vis,,sizeof(vis));
int N;
scanf("%d",&N);
while(N--) {
int Li,Ri,Ti,Bi,t;
scanf("%d%d%d%d%d",&t,&Li,&Ti,&Ri,&Bi);
for(int i=Ti;i<=Bi;i++) {
for(int j=Li;j<=Ri;j++) {
vis[t][i][j]=;
}
}
}
for(int d=;d<;d++) {
for(int i=;i<=T;i++) {
for(int r=;r<=H;r++) {
for(int c=;c<=W;c++) {
if(d==&&i!=) change(r,c,i,i-);
else change(r,c,T-i+,T-i+);
}
}
}
}
int escaped=,unknown=;
memset(res,-,sizeof(res));
for(int i=;i<=T;i++) {
bool is_allone=true;
bool is_twice_one=false;
for(int r=;r<=H;r++) {
for(int c=;c<=W;c++) {
if(!vis[i][r][c]) {
is_allone=false;
if(res[i][]==-) {
res[i][]=r;
res[i][]=c;
}
else if(res[i][]>=) {
res[i][]=-;
is_twice_one=true;
break;
}
}
}
if(is_twice_one) break;
}
if(!is_allone) escaped=;
if(res[i][]>=) unknown=;
}
if(escaped) printf("The robber has escaped.\n");
else if(unknown) printf("Nothing known.\n");
else {
for(int i=;i<=T;i++) {
if(res[i][]>=) {
printf("Time step %d: The robber has been at %d,%d.\n",i,res[i][],res[i][]);
}
}
}
printf("\n");
}
return ;
}
poj-1104 Robbery的更多相关文章
- POJ 3900 The Robbery
大意:和背包的问题相似,第 i 个箱子有 i 颗钻石.钻石的重量,价值给出.然后再M的重量下背尽量多价值的钻石. 思路:直接暴搜然后剪枝.因为数据范围的原因无法用DP. #include <cs ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- OpenJudge 2803 碎纸机 / Poj 1416 Shredding Company
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...
- POJ 1416 Shredding Company【dfs入门】
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Tot ...
- POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 16178 Accepted: 526 ...
随机推荐
- Protractor - 怎样运行
前一篇设置好了Protractor基本运行环境,那怎样运行Protractor呢? 要运行我们的测试脚本,至少需要配置好两个文件: ---Package.json ---conf.js Package ...
- 湖南省web应用软件(中慧杯)
湖南省web应用软件 写这篇博客已经是比完赛的第四天了,我还记得那天下着小雨.我们早早的到了比赛的现场抽检机器,在比赛前一天我很是激动.我还记得我们从学校,去株洲的时候我们的领导来给我加油,特别是我的 ...
- python基础(2):python的安装、第一个python程序
1. 第一个python程序 1.1 python的安装 自己百度,这是自学最基本的,安装一路确定即可,记得path下打钩. 1.2 python的编写 python程序有两种编写方式: 1.进入cm ...
- 转:用 Python 一键分析你的上网行为, 看是在认真工作还是摸鱼
简介 想看看你最近一年都在干嘛?看看你平时上网是在摸鱼还是认真工作?想写年度汇报总结,但是苦于没有数据?现在,它来了. 这是一个能让你了解自己的浏览历史的Chrome浏览历史记录分析程序,当然了,他仅 ...
- 这篇文章带你彻底理解synchronized
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- PlayJava Day009
今日所学: /* 2019.08.19开始学习,此为补档. */ 1.Date工具类: Date date = new Date() ; //当前时间 SimpleDateFormat sdf = n ...
- (一)创建新的react native 应用程序
最近开始学习ReactNative了,首先了解下ReactNative http://wiki.jikexueyuan.com/project/react-native/GettingStarted. ...
- phpstorm xdebug 无法断点调试问题
最近用phpstorm+xdebug调试一段php代码的时候莫名其妙的无法切入断点调试 本地用的php集成环境是UPUPW ANK V1.1.7 64Bit 选择了集成环境中php版本为7.1.x 搞 ...
- 5-2可视化库Seaborn-调色板
In [1]: import numpy as np import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline ...
- java面试填坑解惑篇
感谢原文出处:https://www.cnblogs.com/javazhiyin/ NO1.请简单描述JDK和JRE的区别? NO1.回答JDK和JRE的区别这道题,首先要回答两个名次的概念,JDK ...