博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
阅读量:6324 次
发布时间:2019-06-22

本文共 2415 字,大约阅读时间需要 8 分钟。

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
#include
#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;}

转载于:https://www.cnblogs.com/FlyerBird/p/9052560.html

你可能感兴趣的文章
我的友情链接
查看>>
Java学习日志(17-2-集合框架工具类Arrays及其他特性)
查看>>
HTTP响应头和请求头信息对照表
查看>>
Chrome完美屏蔽优酷广告及黑屏教程
查看>>
一份不错的php面试题(附答案)
查看>>
前端工程资源发布、优化
查看>>
nginx安装(ubuntu14.04)
查看>>
SQLServer2008备份和恢复
查看>>
WinCE 6.0 的编译
查看>>
访问Nginx上的资源时出现403的原因及解决办法
查看>>
大家好,我是蔡某某,刚刚注册的账号,希望大家支持与帮助
查看>>
shell检测输入的IP是否合法
查看>>
30 分钟快速入门 Docker 教程
查看>>
初步计划
查看>>
Ubuntu11.10下编译android源码4.0.3
查看>>
如何关闭 CentOS7 SELinux
查看>>
vsftpd本地用户访问
查看>>
python文件操作学习笔记
查看>>
朗科实习期间心得笔记(六)
查看>>
iphone编程指南学习笔记2
查看>>