NYOJ 309 BOBSLEDDING(细节题)
2017-04-14 15:04
337 查看
本题链接
BOBSLEDDING
时间限制:1000 ms | 内存限制:65535 KB难度:3
描述
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 3 11 1 13 8
样例输出
5
来源第四届河南省程序设计大赛
上传者张云聪贪心题,队友用动态规划做出来了
要对输入的阈(yu)值进行排序!!!! 对7 11 13从小到大排序!!!
绿线是从左向右排查,红线是在绿线基础上从右向左排查,这样能保证结果
给几组测试数据
20 3 7 3 11 1 13 8
14 3 6 3 11 1 13 3
输出 10和5
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; struct point{ int x,v; }; int cmp(point const &a,point const &b){ return a.x<b.x; } int main(){ int n,m,i,j,max,k; while(~scanf("%d%d",&n,&m)){ point p[510]; //阈值 point a[1010]; //所有点的坐标和速度 memset(p,0,sizeof(p)); memset(a,0,sizeof(a)); p[0].x=0; p[0].v=1; for(i=1;i<=m;i++){ scanf("%d%d",&p[i].x,&p[i].v); } sort(p,p+m+1,cmp); a[0].v=1; i=1; for(j=1;j<=m;j++){ while(i<p[j].x){ a[i].v=a[i-1].v+1; i++; } if(i==p[j].x){ if(a[i-1].v>=p[j].v) a[i].v=p[j].v; else a[i].v=a[i-1].v+1; i++; } } //从左到右过一遍 for(j=i;j<=n;j++){ a[j].v=a[j-1].v+1; } //最后一个阈值后可能还有路程,其速度要判断 max=a .v; for(i=n;i>0;i--){ if(a[i-1].v>=a[i].v+1){ a[i-1].v=a[i].v+1; if(max<a[i-1].v) max=a[i-1].v; } } //从右到左过一遍,顺便再记录最大值 printf("%d\n",max); } return 0; }
相关文章推荐
- BOBSLEDDING(一道有趣的贪心题 nyoj309)
- nyoj 309 BOBSLEDDING 【贪心】
- nyoj 309 bobsledding 即河南省第四届大学生程序设计大赛第七题
- nyoj309 BOBSLEDDING(动态规划)
- NYOJ:309 BOBSLEDDING
- NYOJ 309 BOBSLEDDING(dp)
- NYOJ 309
- NYOJ309(数论)
- 309 BOBSLEDDING
- nyoj 949哈利波特(细节题)
- NYOJ BOBSLEDDING
- NYOJ815三角形 细节
- NYOJ 488 素数环 注意细节问题
- nyoj 949哈利波特(细节题)
- nyoj 309
- nyoj 153 BOBSLEDDING
- nyoj 309
- nyoj 309 乘雪橇(模拟)
- nysit 309 BOBSLEDDING
- NYOJ 309