309 BOBSLEDDING
来源:互联网 发布:编程语言工资排行 编辑:程序博客网 时间:2024/05/22 17:02
BOBSLEDDING
- 描述
Dr.Kong has entered a bobsled competition because he hopes his hefty weight will give his an advantage over the L meter course (2 <= L<= 1000). Dr.Kong will push off the starting line at 1 meter per second, but his speed can change while he rides along the course. Near the middle of every meter Bessie travels, he can change his speed either by using gravity to accelerate by one meter per second or by braking to stay at the same speed or decrease his speed by one meter per second.
Naturally, Dr.Kong must negotiate N (1 <= N <= 500) turns on the way down the hill. Turn i is located T_i meters from the course start (1 <= T_i <= L-1), and he must be enter the corner meter at a peed of at most S_i meters per second (1 <= S_i <= 1000). Dr.Kong can cross the finish line at any speed he likes.
Help Dr.Kong learn the fastest speed he can attain without exceeding the speed limits on the turns.
Consider this course with the meter markers as integers and the turn speed limits in brackets (e.g., '[3]'):
0 1 2 3 4 5 6 7[3] 8 9 10 11[1] 12 13[8] 14
(Start) |------------------------------------------------------------------------| (Finish)
Below is a chart of Dr.Kong 's speeds at the beginning of each meter length of the course:
Max: [3] [1] [8]
Mtrs: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Spd: 1 2 3 4 5 5 4 3 4 3 2 1 2 3 4
His maximum speed was 5 near the beginning of meter 4.
- 输入
- There are multi test cases,your program should be terminated by EOF
Line 1: Two space-separated integers: L and N
Lines 2..N+1: Line i+1 describes turn i with two space-separated integers: T_i and S_i - 输出
- Line 1: A single integer, representing the maximum speed which Dr.Kong can attain between the start and the finish line, inclusive.
- 样例输入
14 3 7 311 113 8
- 样例输出
5
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct ts{ int t,s;}a[505];int cmp(struct ts x, struct ts y){ return x.t<y.t;}int main(){ int l,n,i,j,v,max; int spd[1005]; while(~scanf("%d%d",&l,&n)) { v=1; for(i=0;i<n;i++) scanf("%d%d",&a[i].t,&a[i].s); sort(a,a+n,cmp); for(i=j=0;i<n;i++) { while(j!=a[i].t) spd[j++]=v++; if(v>a[i].s) { v=spd[j]=a[i].s; for(int k=j;;k--) { spd[k]=v++; if(spd[k]==spd[k-1] || spd[k]==spd[k-1]-1) break; } v=a[i].s; } } while(j!=l) spd[j++]=v++; spd[j]=v; max=1; for(i=0;i<=l;i++) if(spd[i]>max) max=spd[i]; printf("%d\n",max); }}
- 309 BOBSLEDDING
- nysit 309 BOBSLEDDING
- NYOJ:309 BOBSLEDDING
- nyoj 309 BOBSLEDDING 【贪心】
- BOBSLEDDING
- NYOJ 309 BOBSLEDDING(dp)
- NYOJ 309 BOBSLEDDING(细节题)
- BOBSLEDDING (nyoj309)
- NYOJ BOBSLEDDING
- nyoj 153 BOBSLEDDING
- USACO 2009 Dec Bobsledding
- nyoj309 BOBSLEDDING(动态规划)
- USACO 2009 Dec Bobsledding 滑雪比赛
- 河南第四届ACM省赛(BOBSLEDDING)
- 第四届河南省acm省赛 BOBSLEDDING
- bzoj3411 [Usaco2009 Dec]Bobsledding 高山滑雪
- BOBSLEDDING(一道有趣的贪心题 nyoj309)
- 河南省第四届ACM程序设计大赛 问题 G: BOBSLEDDING
- 对象和C + +
- URAL 1742 Team building
- Linux下DOS攻击探测
- Android之高仿手机QQ聊天
- 2014 Multi-University Training Contest 2--by 镇海中学 解题报告
- 309 BOBSLEDDING
- poj 3090 && poj 2478(法雷级数,欧拉函数)
- 正则表达式基础知识
- DateTime.ToString("yyyy/MM/dd")变成"2011-06-14"的解决方法
- 打算到噶尽快落实到噶尽快落实到噶
- TFS安装使用笔记——TFS非域单服务器配置外网访问
- 312 20岁生日
- 线段树的题目
- 314 斐波那契数列四吧