nyoj309 BOBSLEDDING(动态规划)
2017-04-13 21:46
232 查看
题目309
题目信息
运行结果
本题排行
讨论区
时间限制: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.
样例输入
样例输出
来源第四届河南省程序设计大赛
上传者张云聪
题意就是Dr.Kong滑雪,在滑雪途中会经历N个角落,在经过这些拐角时速度不能大于规定的速度。
如果你在用贪心做,注意点是:不能只注意到离你最近的那个拐角的速度,还要满足离你很远的拐角的速度。
动态规划判断:
共两层循环,第一层为滑雪的长度,第二层为拐角数。
判断当前滑雪位置能满足所有拐角的速度。
dp[i]:为到达i点的速度。
转移方程:
有三种情况:
如果当前位置可以加速,dp[i]=min(dp[i-1]+1,dp[i];
如果当前位置需要减速dp[i]=min(dp[i-1]-1,dp[i]);
如果当前位置需要匀速dp[i]=min(dp[i],dp[i-1]);
初始化时要初始化dp数组为最大值,dp[0]=1.
题目信息
运行结果
本题排行
讨论区
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
来源第四届河南省程序设计大赛
上传者张云聪
题意就是Dr.Kong滑雪,在滑雪途中会经历N个角落,在经过这些拐角时速度不能大于规定的速度。
如果你在用贪心做,注意点是:不能只注意到离你最近的那个拐角的速度,还要满足离你很远的拐角的速度。
动态规划判断:
共两层循环,第一层为滑雪的长度,第二层为拐角数。
判断当前滑雪位置能满足所有拐角的速度。
dp[i]:为到达i点的速度。
转移方程:
有三种情况:
如果当前位置可以加速,dp[i]=min(dp[i-1]+1,dp[i];
如果当前位置需要减速dp[i]=min(dp[i-1]-1,dp[i]);
如果当前位置需要匀速dp[i]=min(dp[i],dp[i-1]);
初始化时要初始化dp数组为最大值,dp[0]=1.
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; struct node { int t; int c; }; int main() { int l,n; int dp[1005]; node x[505]; while(~scanf("%d %d",&l,&n)) { memset(dp,100,sizeof(dp)); memset(x,0,sizeof(x)); for(int i=0;i<n;i++) { scanf("%d %d",&x[i].t,&x[i].c); } int res=0; dp[0]=1; for(int i=1;i<=l;i++) { //标志i处是否还有拐角 bool flag=false; for(int j=0;j<n;j++) { if(x[j].t<i) continue; flag=true; if(dp[i-1]-x[j].c<=x[j].t-i) { if(dp[i-1]-x[j].c-x[j].t+i!=0) { dp[i]=min(dp[i],dp[i-1]+1); } else { dp[i]=min(dp[i],dp[i-1]); } } else { dp[i]=min(dp[i],dp[i-1]-1); } } if(!flag) dp[i]=dp[i-1]+1; res=max(dp[i],res); } printf("%d\n",res); } return 0; }
相关文章推荐
- nyoj 309 bobsledding 即河南省第四届大学生程序设计大赛第七题
- NYOJ:309 BOBSLEDDING
- BOBSLEDDING(一道有趣的贪心题 nyoj309)
- nyoj 309 BOBSLEDDING 【贪心】
- NYOJ 309 BOBSLEDDING(细节题)
- NYOJ 309 BOBSLEDDING(dp)
- nyoj 236心急的C小加 动态规划( java)
- NYOJ练习题 Splits the string (简单动态规划)
- NYOJ 311 完全背包(动态规划)
- NYOJ469(动态规划)
- skiing (NYOJ 10) [动态规划+搜索]
- nyoj--44--子串和(动态规划)
- nyoj 1070 诡异的电梯【Ⅰ】 动态规划
- NYOJ 苹果【动态规划】
- NYOJ-剑客决斗-(动态规划)
- nyoj--16--矩形嵌套(动态规划)
- 【动态规划】NYOJ最长公共子序列
- nyoj-195 飞翔【动态规划】
- NYOJ36 最长公共子序列 【动态规划】
- NYOJ - 814 - 又见拦截导弹(动态规划--最大单调递增子序列变形)