Asia-Tsukuba 2017

Problem C Medical Checkup

题目链接
Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on.

Students are now forming a long queue, waiting for the checkup to start. Students are also numbered 1, 2, 3, and so on, from the top of the queue. They have to undergo checkup items in the order of the item numbers, not skipping any of them nor changing the order. The order of students should not be changed either.

Multiple checkup items can be carried out in parallel, but each item can be carried out for only one student at a time. Students have to wait in queues of their next checkup items until all the others before them finish.

Each of the students is associated with an integer value called health condition. For a student with the health condition h, it takes h minutes to finish each of the checkup items. You may assume that no interval is needed between two students on the same checkup item or two checkup items for a single student.

Your task is to find the items students are being checked up or waiting for at a specified time t.

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

n t
h1

hn
n and t are integers. n is the number of the students (1≤n≤105). t specifies the time of our concern (0≤t≤109). For each i, the integer hi is the health condition of student i (1≤h≤109).

Output
Output n lines each containing a single integer. The i-th line should contain the checkup item number of the item which the student i is being checked up or is waiting for, at (t+0.5) minutes after the checkup starts. You may assume that all the students are yet to finish some of the checkup items at that moment.

Sample Input 1
3 20
5
7
3
Sample Output 1
5
3
2
Sample Input 2
5 1000000000
5553
2186
3472
2605
1790
Sample Output 2
180083
180083
180082
180082
180082

题目描述

有n个人,无限台检测器,每个人必须按顺序经过检测器,第i个人会在每台检测器前检查ai分钟,一台检测器每次只能检测一个人,其他人只能等,问T时刻时,每个人在哪台机器前(包括正在检测或等待)。

代码

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MaxN = 1e5 + 5;

int main() {
    int n, t;
    while(~scanf("%d %d", &n, &t)) {
        LL sum = 0, maxx = 0;
        for(int i = 1; i <= n; i++) {
            LL x; scanf("%lld", &x);
            sum += x, maxx = max(maxx, x);
            LL ans = 1;
            if(sum <= t) ans = floor((t - sum) * 1.0 / maxx) + 2;
            printf("%lld\n", ans);
        }
    }
    return 0;
}

Problem I Starting a Scenic Railroad Service

题目链接

Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be.

A market survey was ordered and Jim has just received an estimated list of passengers’ travel sections. Based on the list, he’d like to estimate the minimum number of train seats that meets the demand.

Providing as many seats as all of the passengers may cost unreasonably high. Assigning the same seat to more than one passenger without overlapping travel sections may lead to a great cost cutback.

Two different policies are considered on seat assignments. As the views from the train windows depend on the seat positions, it would be better if passengers can choose a seat. One possible policy (named `policy-1’) is to allow the passengers to choose an arbitrary seat among all the remaining seats when they make their reservations. As the order of reservations is unknown, all the possible orders must be considered on counting the required number of seats.

The other policy (named `policy-2’) does not allow the passengers to choose their seats; the seat assignments are decided by the railroad operator, not by the passengers, after all the reservations are completed. This policy may reduce the number of the required seats considerably.

Your task is to let Jim know how di erent these two policies are by providing him a program that computes the numbers of seats required under the two seat reservation policies. Let us consider a case where there are four stations, S1, S2, S3, and S4, and four expected passengers p1, p2, p3, and p4 with the travel list below.

passenger from to
p1 S1 S2
p2 S2 S3
p3 S1 S3
p4 S3 S4

The travel sections of p1 and p2 do not overlap, that of p3 overlaps those of p1 and p2, and that of p4 does not overlap those of any others.

Let’s check if two seats would suffice under the policy-1. If p1 books a seat first, either of the two seats can be chosen. If p2 books second, as the travel section does not overlap that of p1, the same seat can be booked, but the other seat may look more attractive to p2. If p2 reserves a seat different from that of p1, there will remain no available seats for p3 between S1 and S3 (Figure I.1).

Figure I.1. With two seats

With three seats, p3 can find a seat with any seat reservation combinations by p1 and p2. p4 can also book a seat for there are no other passengers between S3 and S4 (Figure I.2).

Figure I.2. With three seats

For this travel list, only three seats suffice considering all the possible reservation orders and seat preferences under the policy-1.

On the other hand, deciding the seat assignments after all the reservations are completed enables a tight assignment with only two seats under the policy-2 (Figure I.3).

Figure I.3. Tight assignment to two seats

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

n
a1 b1

an bn
Here, the first line has an integer n, the number of the passengers in the estimated list of passengers’ travel sections (1≤n≤200000). The stations are numbered starting from 1 in their order along the route. Each of the following n lines describes the travel for each passenger by two integers, the boarding and the alighting station numbers, ai and bi, respectively (1≤ai

题目描述

有n个人坐火车,每个人有一个起点和终点,n个人按顺序预定座位,方案一:每个人预定时会优先选择别人没坐过的位置;方案二:每个人预定的位置由售票员决定。问两种方案分别最少需要多少座位。

solution

对于方案一:假设f(p)表示第p个人的区间覆盖数,答案就是max(f(p) + 1)
对于方案二:答案为区间的最大覆盖数
时间这里写链接内容复杂度:O(n)

代码

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int MaxN = 2e5 + 5;

PII a[MaxN];
int ishead[MaxN], istail[MaxN], cnt[MaxN];

int main() {
    int n;
    while(~scanf("%d", &n)) {
        memset(ishead, 0, sizeof(ishead)); 
        memset(istail, 0, sizeof(istail));
        memset(cnt, 0, sizeof(cnt));
        int N = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%d %d", &a[i].first, &a[i].second);
            ishead[a[i].first]++, istail[a[i].second]++;
            cnt[a[i].first]++, cnt[a[i].second]--;
            N = max(N, a[i].second);
        }
        for(int i = 1; i <= N; i++) ishead[i] += ishead[i - 1], istail[i] += istail[i - 1];
        int ans_1 = 0, ans_2 = 0;
        for(int i = 1; i <= n; i++) ans_1 = max(ans_1, ishead[a[i].second - 1] - istail[a[i].first]);
        for(int i = 1; i <= N; i++) ans_2 = max(ans_2, cnt[i] += cnt[i - 1]);
        printf("%d %d\n", ans_1, ans_2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Jasmineaha/article/details/80083705