Fourth session bobsledding, ACM Province, Henan Province

Source: Internet
Author: User

bobsledding time limit: +Ms | Memory Limit:65535KB Difficulty:3
Describe

dr.kong have entered a bobsled competition because he hopes his hefty Wei Ght would give his a advantage over the L meter course (2 <= l<= 1000). Dr.kong would push off the starting line at 1 meter per second, but he 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 he speed by one meter per second.

Naturally, Dr.kong must negotiate N (1 <= n <=) turns on the the-the-the-the-the-the-same-hill. Turn I was located t_i meters from the course start (1 <= t_i <= L-1), and he must being enter the corner meter at a  Peed of 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 is 5 near the beginning of meter 4.

Input
There is multi test Cases,your program should is terminated by EOF
Line 1:two space-separated integers:l and N
Lines 2..n+1:line i+1 describes turn I with II space-separated integers:t_i and s_i
Output
Line
1: A single integer, representing the maximum speed which dr.kong can attain between the start and the finish L INE, inclusive.
Sample input
3                                            7 311 113 8
Sample output
5
Source

Fourth session of Henan Province Program design Competition

Test instructions

Give you the length of the road, and then give you how many corners of the place, that location has a limit speed through, let you ask from 0 to l maximum speed;

Cases

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 2 3 4 5 5 4 3 4 3 2 1 2 3 4

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
int m,n;
int dp[1010];
int main ()
{
while (~SCANF ("%d%d", &m,&n))
{
int i,a,b,j;
Memset (Dp,0,sizeof (DP));
for (i=0;i<n;i++)
{
scanf ("%d%d", &a,&b);
Dp[a]=b;
}
Dp[0]=1;
int C;
for (i=1;i<=m;i++)
{
c=dp[i-1]+1;
if (dp[i]>=c| | dp[i]==0)//dp[i]>=c is to determine whether the speed of this point is greater than the limit speed of this point, dp[i]==0 is this point no limit speed.
dp[i]=c;//the speed update at this time.
Else
{
for (j=i;j>=0;j--)
{
if (dp[j]+1<dp[j-1])//In turn update before the speed, because if you have been accelerating will exceed this limit speed.
dp[j-1]=dp[j]+1;
}
}
}
int max1=-1;
/*for (i=0;i<=m;i++)
{


printf ("%2d", I);
}
printf ("\ n"); */
for (i=0;i<=m;i++)
{
if (Max1<dp[i])
Max1=dp[i];
printf ("%2d", Dp[i]);
}
printf ("%d\n", max1);
}
return 0;
}

Fourth session bobsledding, ACM Province, Henan Province

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.