B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
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 亚洲区(南宁赛区)网络赛的更多相关文章
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- 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 ...
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)
You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 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 题意:给你一串数,给你一个处理方法,确定出这串数的权值, ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!
鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS Memory Limit:262144KB 64bit IO Fo ...
- [刷题]ACM ICPC 2016北京赛站网络赛 D - Pick Your Players
Description You are the manager of a small soccer team. After seeing the shameless behavior of your ...
随机推荐
- 如何用 windows+github搭建一个优美的hexo博客
1.Hexo简单介绍 Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页. 风一般的速度Hexo基于Nod ...
- 抽象工厂模式&简单工厂模式
抽象工厂模式 优点: 如IFactory factory=new AccessFactory(),在一个应用中只需要初始化一次,这就使得改变应用的时候变得非常容易:其次它让具体的创建实例过程与客户端分 ...
- IT小小鸟读书笔记2
Part4: 一. 大学的时光真的很容易荒废,自己的实力到头来和自己的成绩单一样空虚,其实自己也是深有同感的. 二. 这个观点我十分的认同:在某个方面比别人多5%的深度,可能拿到的报酬就是 ...
- vue + element-ui 制作tab切换(适用于单页切换不同标记显示不同内容)
本篇文章使用vue结合element开发tab切换单页不同的标记显示不同的内容. 1.安装element-ui npm install element-ui --save 2.在main.js中引入e ...
- adb工具包究竟能帮我们做什么?
adb工具包主要作用于什么呢?应该有很多用户都不了解adb,那就一起来了解一下吧!adb的全称为Android Debug Bridge,就是起到调试桥的作用. 借助adb工具,我们可以管理设备或手机 ...
- JavaMelody监控spring、struts
前言 前面讲过了Javamelody的基本配置,如何使用Javamelody来监控JDBC以及SQL. 这里继续讲解一下如何监控struts和spring. 手码不易,转载请注明:xingoo 由于s ...
- 【Spring实战】—— 14 传统的JDBC实现的DAO插入和读取
从这篇开始学习Spring的JDBC,为了了解Spring对于JDBC的作用,先通过JDBC传统的流程,实现一个数据库的插入和读取. 从这篇你可以了解到: 1 传统的JDBC插入和读取的过程. 2 如 ...
- ArcGIS10.1之crossdomain文件
大家都知道在10.1之前的版本在开发的时候需要使用跨域部署文件crossdomain.xml文件,在10.1中该文件不需要单独拷贝到IIS根目录或者是java版本的weboutput目录,在serve ...
- Android(java)学习笔记47:通过反射获得构造方法并且使用
1. 获取字节码文件对象: Class c = Class.forName("cn.itcast_01.Person"); 2. 获取构造方法 ...
- Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired,
Did not receive a reply. Possible causes include: the remote application did not send a reply, the m ...