Emergency Evacuation题解

题目

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

Input

The input 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 ≤ r ≤ 500, 1 ≤ s ≤ 500\), and \(1 ≤ p ≤ 2rs.\)

The following \(p\) lines give initial seat positions of the passengers. The \(k\)-th line with \(i_k\) and \(j_k\) means that the \(k\)-th passenger’s seat is in the \(i_k\)-th seat row and it is the \(j_k\)-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 ≤ i_k ≤ r and 1 ≤ j_k ≤ 2s.\) Passengers are on distinct seats, that is, \(i_k != i_l\) or \(j_k != j_l\) holds if \(k != l.\)

Output

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.

Sample

Sample Input 1

5 2 7
1 1
1 2
1 3
2 3
2 4
4 4
5 2

Sample Output 1

9

Sample Input 2

500 500 16
1 1
1 2
1 999
1 1000
2 1
2 2
2 999
2 1000
3 1
3 2
3 999
3 1000
499 500
499 501
499 999
499 1000

Sample Output 2

1008

题解

题目大意

给出每位乘客的座位,问每个乘客都出来最少移动次数。

每次只能移动一个格,一个格里最多有一个人(将座位和过道看做格子)。

解题思路

都出来不好想,可以转换为一个个走到座位的最优方案。

求出每个人走到自己座位的距离,最长的先走。

详细内容看注释

代码

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 5e5+5;
int r, s, n, d[N], ans;
bool judge(int x, int y) {
	return x > y;
}
int main() {
	scanf("%d%d%d", &r, &s, &n);
	for(int i = 0, x, y; i < n; i++)
		scanf("%d%d", &x, &y),
		d[i] = r - x + 1 + (y > s ? y - s : s - y + 1);//三目运算符
	sort(d, d+n, judge);//从大到小排序
	for(int i = 0; i < n; i++)//第i个人在第i秒出发前面有i-1秒
		ans = max(ans, i + d[i]);//所以i从0开始
	printf("%d", ans);
	return 0;
}

原文地址:https://www.cnblogs.com/Z8875/p/12675580.html

时间: 2024-08-01 18:02:54

Emergency Evacuation题解的相关文章

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

ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 我们考虑每个人的路线,如果这两个人在没有阻挡的情况下,到达终点的时间是一样的话,那么必定会在某一点相遇. 此时就需要有一个人要等一个时刻,如果有第三个人的话,这第三个就要等两个时刻,那么我们直接算出每个人到终点的时间,排序后依次后延即可. #include <cstdio> #include &

Emergency Evacuation(贪心)

题目描述(中文版)                                                                                       紧急疏散                                                                                          时间限制:3秒日本政府计划到2020年将入境游客人数增加到4000万,到2030年增加到6000万.不仅要增加游客的吸引

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 (Gym - 102082)

2018-2019, ICPC, Asia Yokohama Regional Contest 2018 A - Digits Are Not Just Characters 签到. B - Arithmetic Progressions 题意:从给定的集合中选出最多的数构成等差数列. 题解:数字排序后,设\(dp[i][j]\)表示等差数列最后一个数字为\(a[i]\),倒数第二个数字为\(a[j]\)的最大个数.然后对于每一位枚举 \(i\),\(lower\_bound()\)找有无合法的

2019 ICM Problem D: Time to leave the Louvre

2019 ICMProblem D: Time to leave the LouvreThe increasing number of terror attacks in France[1]requires a review of the emergencyevacuation plans at many popular destinations. Your ICM team is helping to design evacuationplans at the Louvre in Paris,

题解 poj3057 Evacuation

算法:匈牙利算法 复杂度:不好算,懒得算 这道题我调了两个半小时,代码长,细节多,现总结一下栽过的坑 此题数组传参的方式很好,能够降低代码难度,值得学习 如何使人和时间.门的二元组互不冲突很重要 如果点无冲突用链表,否则用vector 点是从0开始建的,初始化match数组不能用0,我虽然注意到了这一点却没调出来 丑陋的代码 #include<iostream> #include<cstdio> #include<cstring> #include<vector&

解题报告 之 POJ3057 Evacuation

解题报告 之 POJ3057 Evacuation Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time

Codeforces Gym 100002 E &quot;Evacuation Plan&quot; 费用流

"Evacuation Plan" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal workers in case 

解题报告 之 POJ2175 Evacuation Plan

解题报告 之 POJ2175 Evacuation Plan Description The City has a number of municipal buildings and a number of fallout shelters that were build specially to hide municipal workers in case of a nuclear war. Each fallout shelter has a limited capacity in term

codechef Three Way Communications 题解

The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they