2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation

来源:互联网 发布:python中pyparsing 编辑:程序博客网 时间:2024/05/22 07:59

You are given a list of train stations, say from the station 11 to the station 100100.

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 11 to the station 100100 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 11 to station 1010 can share a seat with another passenger from station 3030to 6060.

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.

样例输入

21 10 820 50 2032 30 520 80 2040 90 400

样例输出

2060*

题目来源

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛



题意:每到一个车站有人下车和上车……求需要的最少座位数

解题思路:由于车站很少……直接模拟上下车的过程即可……


#include<iostream>#include<algorithm>#include<math.h>using namespace std;typedef long long int ll;struct point{int shang;int xia;ll k;}list[1005];bool cmp(point a,point b){if(a.shang==b.shang)return a.xia<b.xia;elsereturn a.shang<b.shang;}int main(){int n;while(~scanf("%d",&n)){if(n==0){printf("*\n");break;}ll ans=0;ll mmm=0;for(int i=0;i<n;i++){scanf("%d%d%lld",&list[i].shang,&list[i].xia,&list[i].k);}sort(list,list+n,cmp);for(int i=0;i<100;i++){for(int j=0;j<n;j++){if(list[j].xia==i){ans-=list[j].k;}if(list[j].shang==i){ans+=list[j].k;mmm=max(mmm,ans);}}}printf("%lld\n",mmm);}return 0;}



阅读全文
0 0
原创粉丝点击