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

本文介绍了一个算法问题,即如何计算一列火车从起点到终点所需的最少座位数量,以满足所有乘客的需求而没有冲突。该算法考虑了乘客在不同站点上下车的情况,并通过模拟过程解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

样例输入
2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0
样例输出
20
60
*
题目来源

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;
	else
	return 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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值