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 105
int 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;
}

B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛的更多相关文章

  1. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  2. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem【状态压缩】

    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛  M. Frequent Subsets Problem 题意:给定N和α还有M个U={1,2,3,...N}的子集,求子集X个数,X满足:X是U ...

  3. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  4. 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)

    You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...

  5. 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit    1000 ms Memory li ...

  6. 2017 ACM/ICPC Asia 南宁区 L The Heaviest Non-decreasing Subsequence Problem

    2017-09-24 20:15:22 writer:pprp 题目链接:https://nanti.jisuanke.com/t/17319 题意:给你一串数,给你一个处理方法,确定出这串数的权值, ...

  7. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  8. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

  9. [刷题]ACM ICPC 2016北京赛站网络赛 D - Pick Your Players

    Description You are the manager of a small soccer team. After seeing the shameless behavior of your ...

随机推荐

  1. zookeeper入门教程

    zookeeper使用场景,不是很难了解,感觉zk监听节点变化,这个功能比较厉害.zk存储的节点组织结构有点像unix文件系统 1.安装zk 运行环境 centos 7 java 8 zookeepe ...

  2. 自己动手实现STL 01:内存配置器的实现(stl_alloc.h)

    一.前言 在STL中,容器是其中的重中之重,基本的STL中的算法,仿函数等都是围绕着容器实现的功能.而,内存配置器,是容器的实现的基础.所以,我第一次要去编写便是内存配置器的实现.在STL中,内存配置 ...

  3. C#简单实现读取txt文本文件并分页存储到数组

    最近做一个VR项目,需要把某个中草药的介绍信息分页显示到unity场景里然后用VR手柄切换信息. unity的脚本是c#,就先在本地写了个代码测试了一下,利用控制台测试输出,到时候拷贝函数过去再结合交 ...

  4. Java程序员应该知道的linux命令

    1.查看Java进程:ps -ef|grep java,ps auxf|grep jva; 2.杀死所有Java进程: pkill java, kill -9 进程ID: 3.进入目录:cd /usr ...

  5. JavaScript写的随机选人真实案例

    JavaScript写的随机选人真实案例 因工作需要,写了一个随机选人的小网页,先看效果图. 背景也是动态的,只不过在写的时候碰到个问题,就是如果把生成动态流星雨的画布放到上生成随机数的操作界面之上的 ...

  6. Scrapy框架之日志等级和请求传参

    一.Scrapy的日志等级 在使用scrapy crawl spiderFileName运行程序时,在终端里打印输出的就是scrapy的日志信息. 1.日志等级(信息种类) ERROR:错误 WARN ...

  7. 安装Android Studio的问题

    大陆墙内安装最新Android Studio多出了很多问题,不使用VPN的话,注意以下问题: 1 一直停留在fetching Android sdk compoment information界面 A ...

  8. ArcGIS Enterprise 10.5.1 静默安装部署记录(Centos 7.2 minimal)- 6、总结

    安装小结 安装完成后,首先我们需要将Datastore托管给Server,再将Server托管给Portal以此来完成整个单机版Enterprise 部署流程.为了测试流程是否正确,我们可以采用上传一 ...

  9. js:JSON对象与JSON字符串转换

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式. 同时,JSON是 JavaScript 原生格式,这 ...

  10. JAVA利用poi获取world文件内容

    本文主要简单介绍了利用poi包,读取world文件内容. 这个依然存在版本的问题,只能读取doc结尾的老版本文件. 话不多说,上代码: import java.io.File; import java ...