码迷,mamicode.com
首页 > 其他好文 > 详细

BOBSLEDDING(一道有趣的贪心题 nyoj309)

时间:2015-04-21 18:12:21      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:动态规划

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
来源
第四届河南省程序设计大赛
上传者

张云聪

题意: Mr。kong 要去滑雪 雪道长L 有n个拐点 速度不能超过某个值

一开始 你速度每米增加1 如果保持不变 下一秒每秒减去1

问你在长度为l 雪道上出现的速度 最高为多少

思路: 每次从拐点开始往回减小 入门前一个比当前的值+1要大 的时候

#include<bits/stdc++.h>
using namespace std;
struct point
{
    int x,y;
}p[505];
int l,n;
int sp[1005];
int a,b;

int cmp(point a,point b)
{
    return a.x<b.x;
}

int main()
{
    int l,n;
    while(~scanf("%d%d",&l,&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].x,&p[i].y);

        sort(p,p+n,cmp);

        sp[0] = 1;
        for(int i=1;i<=l;i++)//初始
            sp[i]=sp[i-1] + 1;
        for(int i=0;i<n;i++)
        {
            a=p[i].x;
            b=p[i].y;
            if(sp[a]>b) sp[a] = b;// 拐点限制的值
            for(int j=a-1;sp[j]>sp[j+1]+1&&j>=0;j--)//开始递减
            {
                sp[j] = sp[j+1] + 1;
            }
        }
        int Mx=sp[0];
        for(int i=1;i<=l;i++)
        {
            if(sp[i]>sp[i-1]+1) sp[i] = sp[i-1]+1;
            Mx=max(Mx,sp[i]);
        }
        printf("%d\n",Mx);
    }
}


BOBSLEDDING(一道有趣的贪心题 nyoj309)

标签:动态规划

原文地址:http://blog.csdn.net/u012349696/article/details/45171629

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!