Train Seats Reservation
来源:互联网 发布:高仿mcm怎么在淘宝买 编辑:程序博客网 时间:2024/05/01 08:28
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, n, which can be as large as 1000. After n, there will be n lines representing the nreservations; each line contains three integers s,t,k, which means that the reservation needs k seats from the station s to the station t .These ticket reservations occur repetitively in the input as the pattern described above. An integer n=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*
思路:
按左边的站排序,暴力枚举比较。
代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct poin{ int l,r,v;}a[1005];int b[100];bool cmp(poin a,poin b){ if(a.l<b.l)return 1; else if(a.l==b.l&&a.r<b.r)return 1; else return 0;}int main(){ int n; while(cin>>n) { if(n==0)break; memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { int q,w,e; scanf("%d%d%d",&q,&w,&e); a[i].l=q;a[i].r=w;a[i].v=e; } sort(a+1,a+n+1,cmp); int sum=a[1].v; for(int i=2;i<=n;i++) { memset(b,0,sizeof(b)); for(int j=1;j<i;j++) { if(a[i].l<a[j].r){sum=max(sum,a[i].v+a[j].v);b[j]=1;} else {sum=max(sum,a[i].v);} } int su=a[i].v; for(int j=1;j<i;j++) { if(b[j])su+=a[j].v; } sum=max(su,sum); } printf("%d\n",sum); } printf("*"); return 0;}
- Train Seats Reservation
- Train Seats Reservation
- ???Train Seats Reservation
- Train Seats Reservation 2017ACM南宁网络赛
- 2017南宁网络赛B.Train Seats Reservation(初级扫描)
- 2017 icpc 南宁赛区 B.Train Seats Reservation(水题)
- B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B.Train Seats Reservation(模拟)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation
- Train Seats Reservation 区间加减 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Train Seats Reservation
- ACM 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛Train Seats Reservation(树状数组的运用)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛-- B. Train Seats Reservation-(区间更新,单点查询思想)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 B. Train Seats Reservation 和 F. Overlapping Rectangles
- Leetcode-Sprial Matrix II
- 服务器没空间的“外包”馊主意
- 1-2-3
- 人毁谤、侮辱、骂时,“阿弥陀佛,谢谢,消灾免难”
- Linux 硬盘块拷贝命令-dd
- Train Seats Reservation
- 转
- linux命令文本操作随笔记
- 第一次工业革命(三)——蒸汽船的发展
- JDBC进阶
- 第四周项目4---建设双链表算法库
- SQL事务回滚
- Kafka简介
- JavaScript--9.字符串拼接