BOBSLEDDING (nyoj309)

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


题意:一个人去滑雪,从起点开始可以一直加速,但路上会有一些转弯,要求路过该点时不能大于该点限制的速度,求一路上最大的速度是多少?

思路:

将限制速度的点初始为该点的速度,其他点初始为0,然后累加,判断是否小于该点的速度,如果小于,继续累加,如果大于,那就从该点往前初始化,知道前后两点的差值不大于1;

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstring>
#include<stack>
#include<stdlib.h>
#include<ctype.h>
using namespace std;
#define MAXN 1300
#define inf 100000

int dp[MAXN];
int main()
{
    int L,n,p,s;
    while(scanf("%d%d",&L,&n)!=EOF)
    {
        memset(dp,0,sizeof dp);
        while(n--)
        {
            cin>>p>>s;
            dp[p]=s;
        }
        int _nows=1,_nowp=1;
        for(int i=0;i<=L;i++)
        {
            if(dp[i]==0)
                dp[i]=_nows;
            else
            {
                if(dp[i-1]<dp[i])
                    dp[i]=dp[i-1]+1;//如果小于限制速度,那就继续加速
                else
                {
                    _nowp=i;
                    while(dp[_nowp-1]-dp[_nowp]>1)//如果超过限制虚度了从该点往前更新
                    {
                        dp[_nowp-1]=dp[_nowp]+1;
                        _nowp--;
                    }
                }
            }
            _nows=dp[i]+1;
        }

        int mmax = 0;
        for(int i = 0; i <= L; i++)
            if(dp[i] > mmax)
                mmax = dp[i];
        printf("%d\n",mmax);
    }
}
在最后的查询中我想用max_element()函数来求最大值(主要是懒),但总是不过,我测试过就是因为这个函数的原因,但我以前用过这个函数,OJ也接受了,这次却不对了,不解啊!求大神数据


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值