关闭

河南省第四届ACM程序设计大赛 问题 G: BOBSLEDDING

153人阅读 评论(0) 收藏 举报
分类:

问题 G: BOBSLEDDING

时间限制: 1 Sec  内存限制: 128 MB
提交: 85  解决: 23
[提交][状态]

题目描述

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.

输入

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 37 311 113 8

样例输出

5

提示

[提交][状态]

题意:一个人在滑雪的过程中可以每秒加速1m/s,也可以保持速度不变,还可以每秒减速1m/s。滑道长L米,有n个拐角,当人滑行到拐角i时,他的速度不能超过Si。问在整个滑行过程中,人的最大速度是多少。

分析:假设人可以一直加速,从前往后遍历每个区间,当到某个拐角时的速度大于这个拐角的最大速度时,就向前更新前面的点的最大速度。dp[i]表示在第i米时可以滑行的最大速度。


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f


#define N 1100
int dp[N],a[N];


int main()
{
    int n,l,i,j,s,t,max;
    while(scanf("%d%d",&l,&n)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        memset(a,0,sizeof(a));
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&t,&s);
            a[t]=s;
        }
        max=0;
        dp[0]=1;
        for(i=1;i<=l;i++)
        {
            dp[i]=dp[i-1]+1;
            if(dp[i]>a[i] && a[i]!=0)
            {
               j=i;
               dp[i]=a[i];
               while(dp[j-1]>dp[j]+1)  ///这里 需要注意一下~~wa了好几次~
               {
                   dp[j-1]=dp[j]+1;
                   j--;
               }
            }
        }


        for(i=0;i<=l;i++)
        {
            if(max<dp[i])
                max=dp[i];
        }
        printf("%d\n",max);
    }
    return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:54241次
    • 积分:3096
    • 等级:
    • 排名:第11603名
    • 原创:262篇
    • 转载:15篇
    • 译文:0篇
    • 评论:21条
    最新评论