The Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing

tourism infrastructure further is indispensable to accomplish such numbers.

One possible enhancement on transport is providing cars extremely long and/or wide, carrying many passengers at a time. Too large a car, however, may require too long to evacuate all

passengers in an emergency. You are requested to help estimating the time required.

The car is assumed to have the following seat arrangement.

  • A center aisle goes straight through the car, directly connecting to the emergency exit

    door at the rear center of the car.
  • The rows of the same number of passenger seats are on both sides of the aisle.

    A rough estimation requested is based on a simple step-wise model. All passengers are initially

    on a distinct seat, and they can make one of the following moves in each step.
  • Passengers on a seat can move to an adjacent seat toward the aisle. Passengers on a seat

    adjacent to the aisle can move sideways directly to the aisle.
  • Passengers on the aisle can move backward by one row of seats. If the passenger is in front of the emergency exit, that is, by the rear-most seat rows, he/she can get off the car.

The seat or the aisle position to move to must be empty; either no other passenger is there before the step, or the passenger there empties the seat by moving to another position in the

same step. When two or more passengers satisfy the condition for the same position, only one of them can move, keeping the others wait in their original positions.

The leftmost figure of Figure C.1 depicts the seat arrangement of a small car given in Sample Input 1. The car have five rows of seats, two seats each on both sides of the aisle, totaling twenty. The initial positions of seven passengers on board are also shown.

The two other figures of Figure C.1 show possible positions of passengers after the first and the second steps. Passenger movements are indicated by fat arrows. Note that, two of the passengers in the front seat had to wait for a vacancy in the first step, and one in the second row had to wait in the next step.

Your task is to write a program that gives the smallest possible number of steps for all the passengers to get off the car, given the seat arrangement and passengers’ initial positions.

输入格式

The input consists of a single test case of the following format.

put consists of a single test case of the following format.

\(
r\ s\ p\\
i_1\ j_1\\
.\\
.\\
.\\
i_p\ j_p\\
\)

Here, \(r\) is the number of passenger seat rows, \(s\) is the number of seats on each side of the aisle, and \(p\) is the number of passengers. They are integers satisfying \(1 \le r \le 500, 1 \le s \le 500\), and \(1 \le p \le 2rs\).

The following \(p\) lines give initial seat positions of the passengers. The k-th line with ik and \(jk\) means that the k-th passenger’s seat is in the ik-th seat row and it is the jk-th seat on that row.

Here, rows and seats are counted from front to rear and left to right, both starting from one.

They satisfy \(1 \le ik \le r\) and \(1 \le jk \le 2s\). Passengers are on distinct seats, that \(i_s, i_k \ne i_l\) or \(j_k \ne j_l\) holds if \(k \ne l\).

输出格式

The output should be one line containing a single integer, the minimum number of steps required for all the passengers to get off the car.

样例输入1

  1. 5 2 7
  2. 1 1
  3. 1 2
  4. 1 3
  5. 2 3
  6. 2 4
  7. 4 4
  8. 5 2

样例输出1

  1. 9

样例输入2

  1. 500 500 16
  2. 1 1
  3. 1 2
  4. 1 999
  5. 1 1000
  6. 2 1
  7. 2 2
  8. 2 999
  9. 2 1000
  10. 3 1
  11. 3 2
  12. 3 999
  13. 3 1000
  14. 499 500
  15. 499 501
  16. 499 999
  17. 499 1000

样例输出2

  1. 1008

题解

这个题还有点绕,但是想通了之后就简单了

首先假设不会有人挡住别人,这样很容易求出来每个人的时间,但是这时候就会发现,会有人一起到达出口,而假设实际上是不成立的,所以需要依次延后.

比如某个时间有3个人同时到达了出口,那么这一秒只能有一个人出去,而剩下的两个人只能再接下来的两秒出去.

这又遇到一个问题,如果这两个人等待的时候,后面又有人被堵了,怎么办?只能继续延后,这样延后到都出去.

如果真的是一个一个出去的话,显然答案就是人数,但是实际上可能又空缺,而这个空缺数量也不难算,当出口出现堵塞的时候,看看最后延后到哪里,如果从现在到堵塞结束的时间都没有人到达出口,就出现了空缺.

把接下来第一个到达出口的时间和堵塞结束的时间相减,就得出了空缺大小,人数加上总的空缺大小,就是最后的答案

代码

  1. #include <cstdio>
  2. #define max(a, b) ((a) > (b) ? (a) : (b))
  3. int cnt[2010], r, s, p, y, x, last, ans;
  4. int main() {
  5. scanf("%d%d%d", &r, &s, &p);
  6. for (int i = 1; i <= p; i++) {
  7. scanf("%d%d", &y, &x);
  8. cnt[max(s - x + 1, x - s) + r - y + 1]++; // 下标是时间,记录这个时间有多少人到达出口(若人不挡人)
  9. }
  10. for (int i = 1; i < 2010; i++)
  11. if (cnt[i])
  12. if (last >= i - 1) // last是堵塞结束的时间
  13. last = cnt[i] + last; // 继续延后
  14. else {
  15. ans += i - last - 1; // 记录空缺
  16. last = i - 1 + cnt[i]; // 更新last
  17. }
  18. printf("%d", ans + p);
  19. return 0;
  20. }

Emergency Evacuation 题解的更多相关文章

  1. ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)

    ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 ...

  2. Emergency Evacuation,题解

    题目: 题意: 在某一秒,每个人可以进行一个移动:去旁边座位,去过道,在过道向出口走,求最少多少秒可以让所有人离开(具体如图和样例). 分析: 首先,我们先考虑简单的,只考虑出口前有什么事件发生:1. ...

  3. POJ 3057 Evacuation 题解

    题目 Fires can be disastrous, especially when a fire breaks out in a room that is completely filled wi ...

  4. codeforces gym #102082C Emergency Evacuation(贪心Orz)

    题目链接: https://codeforces.com/gym/102082 题意: 在一个客车里面有$r$排座位,每排座位有$2s$个座位,中间一条走廊 有$p$个人在车内,求出所有人走出客车的最 ...

  5. POJ3057:Evacuation——题解

    http://poj.org/problem?id=3057 题目大意: .为人,D为门,X为障碍,门每秒只能出去一个人,问多少秒出光. 如果无法出光输出impossible. ——————————— ...

  6. Emergency Evacuation(最短下车时间)———(思维)

    题意: 给你一个车厢和一些人的位置,这些人都坐在座位上,求这些人全部出去的时间最小值. 注意: 有许多行座位,且每行关于过道对称,出口在过道一端,一个时间只能移动一个单位,且每时刻每个格子只能有一人 ...

  7. 【贪心】Emergency Evacuation

    题目 大致题意 把指定的人从同一出口送出车外,且同一位置不能同时有两个人,求所需的最短时间. 分析 第一感觉就是利用贪心思想解决问题,但是这道题的数据范围用模拟的话肯定是会爆掉的,所以这是不可取的.我 ...

  8. Problem C Emergency Evacuation 一道思维题

    题目描述 输入 输出 样例 样例输入 样例输入一 样例输入二 样例输出 样例输出一 9 样例输出二 1008 一句话题意:给你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值. 分析 ...

  9. 【贪心算法】CF Emergency Evacuation

    题目大意 vjudge链接 给你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值. 样例1输入 5 2 71 11 21 32 32 44 45 2 样例1输出 9 样例2输入 50 ...

随机推荐

  1. PAT 害死人不偿命的(3n+1)猜想

    卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 ( 3n+1 )砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在 195 ...

  2. 【Spring注解开发】组件注册-使用@Configuration和@Bean给容器中注册组件

    写在前面 在之前的Spring版本中,我们只能通过写XML配置文件来定义我们的Bean,XML配置不仅繁琐,而且很容易出错,稍有不慎就会导致编写的应用程序各种报错,排查半天,发现是XML文件配置不对! ...

  3. 【分区】使用 GPT 分区表分区并格式化 (非 FreeBSD 系统)

    新购买的 Linux 云服务器,由于数据盘未做分区和格式化,无法使用. 注意: 数据盘中的数据在格式化后将全部被清空.请在格式化之前,确保数据盘中没有数据或已对重要数据进行备份.为避免服务发生异常,格 ...

  4. .NET Core加解密实战系列之——RSA非对称加密算法

    目录 简介 功能依赖 生成RSA秘钥 PKCS1格式 PKCS8格式 私钥操作 PKCS1与PKCS8格式互转 PKCS1与PKCS8私钥中提取公钥 PEM操作 PEM格式密钥读取 PEM格式密钥写入 ...

  5. 在Centos7中,从主机 Windows 上无法远程访问 Linux 上rabbitmq的解决方法

    当在 Linux 上配置好 Rabbitmq服务器后,如果从主机中无法访问到 Linux 中的Rabbitmq服务器时,需要做如下的检查: 1. Rabbitmq是否启动成功 在控制台输入: ps - ...

  6. WEB应用的常见安全漏洞

      01. SQL 注入 SQL 注入就是通过给 web 应用接口传入一些特殊字符,达到欺骗服务器执行恶意的 SQL 命令.SQL 注入漏洞属于后端的范畴,但前端也可做体验上的优化.原因:当使用外部不 ...

  7. MySQL-数据库和表的基本操作

    数据库和表的基本操作 数据库基础知识 创建数据库 CREATE DATABASE 数据库名称 ; 查看数据库(显示数据库名列表) SHOW DATABASES ; 查看某数据库信息(显示创建的信息) ...

  8. 《Java核心技术》笔记:第7章 异常、断言和日志

    1. 异常 (P 280)异常处理需要考虑的问题: 用户输入错误 设备错误 物理限制 代码错误 (P 280)传统的处理错误的方法是:返回一个特殊的错误码,常见的是返回-1或者null引用 (P 28 ...

  9. gatewayworker 安装 pcntl 扩展

    安装其它扩展也是如此. 第一步,查看php版本: /phpstudy/server/php/bin/php -v 第二步,下载扩展文件: http://php.net/releases/  这里面寻找 ...

  10. 使用docker创建rocketMQ容器

    一.rocketMQ安装 (一)安装NameSrv 1.创建nameSrv数据挂载文件夹 mkdir -p /usr/data/rocketMQ/data/namesrv/logs mkdir -p ...