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. CSS Hack兼容

    CSS中有很多标签在不同浏览器中有不同的兼容性问题,问了让网页的功能更好的不同浏览器中显示正常, 需要通过hack的方式来解决浏览器兼容问题. CSS hack问题由来已久,目前我的了解甚少,以下是转 ...

  2. Android开发之EditText利用键盘跳转到下一个输入框

    以前做项目的时候,从来没考虑过这些.这段时间公司内部用的一款APP,就出现了这个问题,在登录或者注册的时候,点击键盘的回车按钮,可以跳到下一个输入框的功能,这个属性一直也没记住,今天就把自己一直没记过 ...

  3. [转]滚动视差?CSS 不在话下/background attachment

      何为滚动视差 视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验. 作为网页设计的热点趋势,越来越多的网站应用了这项技术. ...

  4. axios 发 post 请求,后端接收不到参数的解决方案

    问题场景 场景很简单,就是一个正常 axios post 请求: axios({ headers: { 'deviceCode': 'A95ZEF1-47B5-AC90BF3' }, method: ...

  5. 关于window的端口查看及tomcat的端口修改问题

    1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\>netstat -ano 协议    本地地址                     外部地址  ...

  6. iDempiere 使用指南 绿色版一键启动测试环境

    Created by 蓝色布鲁斯,QQ32876341,blog http://www.cnblogs.com/zzyan/ iDempiere官方中文wiki主页 http://wiki.idemp ...

  7. 安装lombok(eclipse)

    下载 lombok.jar (https://projectlombok.org/download.html) 将 lombok.jar 放在eclipse安装目录下,和 eclipse.ini 文件 ...

  8. 任务二:零基础HTML及CSS编码练习

    任务目的 针对设计稿样式进行合理的HTML架构,包括以下但不限于: 掌握常用HTML标签的含义.用法 能够基于设计稿来合理规划HTML文档结构 理解语义化,合理地使用HTML标签来构建页面 掌握基本的 ...

  9. haproxy学习——简介、基本配置(二)

    官网:http://www.haproxy.org/ 个人感觉haproxy学习的重点在于配置上,把配置文档搞懂了就明白大部分套路了.不过本篇内容属于入门学习:1.使用haproxy简单的实现负载均衡 ...

  10. Java—集合框架Map

    Map接口 Map提供了一种映射关系,其中的元素是以键值对(key-value)的形式存储的,key和value可以是任意类型的对象,能够实现根据key快速查找value. Map中的键值对以Entr ...