B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
来源:互联网 发布:淘宝美工可以用素材网 编辑:程序博客网 时间:2024/05/21 21:38
You are given a list of train stations, say from the station 1 to the station 100.
The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station 1 to the station 100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.
Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station 1 to station 10 can share a seat with another passenger from station 30 to 60.
Input Format
Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders, nn, which can be as large as 10001000. After nn, there will be nn lines representing the nn reservations; each line contains three integers s, t, ks,t,k, which means that the reservation needs kk seats from the station ss to the station tt .These ticket reservations occur repetitively in the input as the pattern described above. An integer n = 0n=0 (zero) signifies the end of input.
Output Format
For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star ‘*’ to signify the end of outputs.
样例输入
2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0
样例输出
20
60
题目分析:
有1-100个站点,乘客将会下订单预定从 s 站点到 t 站点中的 k 个座位,不同区间的座位之间可以自由分享,比如从1-30站点的座位可以给50-80站点的乘客。题目要我们找出每个样例中所需要的最小座位数。注意:1-10的座位也可以给10-20的乘客
我的思路:
对每一个站点都计算:
由于数据比较小,进行区间覆盖,一个区间的需要的座位数覆盖到每一个站点上去,这样当所有的区间都覆盖完成之后,所有的站点需要的座位数就会出现一个峰值,那个峰值就是我们想要的。
完整代码:
#include<stdio.h>#include<string.h>#define MAX 105int main(void){ int n, s, t, k, max, seat[MAX]; while (scanf("%d", &n)!=EOF) { max = 0; memset(seat, 0, sizeof(int)*MAX); if (n == 0) { printf("*\n"); break; } while (n-- > 0) { scanf("%d%d%d", &s, &t, &k); for (int i = s; i < t; i++) seat[i] += k; } for (int i = 1; i < MAX; i++) { if (seat[i] > max) max = seat[i]; } printf("%d\n", max); } return 0;}
- ACM 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B.Train Seats Reservation(模拟)
- B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation
- Train Seats Reservation 区间加减 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation(贪心问题+区间覆盖)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛-- B. Train Seats Reservation-(区间更新,单点查询思想)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation 和 F. Overlapping Rectangles
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛Train Seats Reservation(树状数组的运用)
- 2017 icpc 南宁赛区 B.Train Seats Reservation(水题)
- Train Seats Reservation 2017ACM南宁网络赛
- 2017南宁网络赛B.Train Seats Reservation(初级扫描)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- Werkzeug 之数据结构解读不可变类
- Java Persistence with MyBatis 3(中文版) 第二章 引导MyBatis
- 重定向和转发的区别
- HashMap原理详解
- tensorflow中的变量和占位符
- B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- gcd&exgcd
- Java Persistence with MyBatis 3(中文版) 第三章 使用XML配置SQL映射器
- 使用阿里巴巴图标库生成iconfont字体图标
- XILINX K7 DDR3引脚验证总结
- 设备模型
- angular4实战(2) router
- DFS的应用——Binary Tree Paths
- 归并排序与快速排序