第四届河南省acm省赛 BOBSLEDDING

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
来源

第四届河南省程序设计大赛

题意:

给你L长度的路,然后给你多少个转弯的地点,那个地点有个限制速度通过的,让你求从0到L之间的最大速度;

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是判断到这个点的速度是否大于这个点的限制速度,dp[i]==0是这个点没有限制速度。

dp[i]=c;//此时速度更新。

else

{

for(j=i;j>=0;j--)

{

if(dp[j]+1<dp[j-1])//反过来更新之前的速度,因为你如果一直加速会超过这个限制速度。

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;

}

时间: 2024-11-09 01:57:45

第四届河南省acm省赛 BOBSLEDDING的相关文章

第四届河南省acm省赛 走迷宫(二分法枚举差值和最大值最小值+DFS)

走迷宫 时间限制:1000 ms  |  内存限制:65535 KB 难度:5 描述 Dr.Kong设计的机器人卡多非常爱玩,它常常偷偷跑出实验室,在某个游乐场玩之不疲.这天卡多又跑出来了,在SJTL游乐场玩个不停,坐完碰碰车,又玩滑滑梯,这时卡多又走入一个迷宫.整个迷宫是用一个N * N的方阵给出,方阵中单元格中填充了一个整数,表示走到这个位置的难度. 这个迷宫可以向上走,向下走,向右走,向左走,但是不能穿越对角线.走迷宫的取胜规则很有意思,看谁能更快地找到一条路径,其路径上单元格最大难度值与

[河南省ACM省赛-第四届] 表达式求值(nyoj 305)

栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cstdlib> #include<algorithm> #include<stack> using namespace std; string getPostfixExp(string s) { stack<char> sta;// d

[河南省ACM省赛-第四届] 序号互换 (nyoj 303)

相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cstdlib> #include<algorithm> #include<stack> using namespace std; int main(){ int t; string s; cin>>t; while(t--) {

[河南省ACM省赛-第四届] Substring (nyoj 308)

练习使用字符串函数了. 1.字串的反转也是它的字串,2.最长,3.最先出现 string: #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; int main() { int t, n; string s; cin>>t; while(t--){ cin>&

[河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostream> #include<cstdio> #include<cstring> #include<vector> using namespace std; #define N 10002 vector<int> g[N]; int main() { freo

[河南省ACM省赛-第五届] 最强DE 战斗力 (nyoj 541)

题解链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=541 几天前百度题解后用数学知识AC的,后来大牛说这是一道动态规划题. 网上的数学解题链接:http://blog.csdn.net/x314542916/article/details/8204583 d(i) = max{d(j)*d(n-j) | 1<= j <=n/2}; 用Java写比较简单 import java.math.BigInteger; import java.u

[河南省ACM省赛-第三届] 房间安排 (nyoj 168)

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define N 200 int day[N];//day[i] 第i天的最多房间数 int main() { fre

[河南省ACM省赛-第三届] AMAZING AUCTION (nyoj 251)

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=251 规则: 1.若某竞标价唯一,则胜出 2.若不存在唯一竞标价,则投标次数最少竞标价中标,存在多个时,选择价钱最低且最先投此价钱的为中标 #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 102 #define M 1002 struct N

第五届河南省acm省赛 最强DE 战斗力

最强DE 战斗力 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 春秋战国时期,赵国地大物博,资源非常丰富,人民安居乐业.但许多国家对它虎视眈眈,准备联合起来对赵国发起一场战争. 显然,面对多个国家的部队去作战,赵国的兵力明显处于劣势.战斗力是决定战争成败的关键因素,一般来说,一支部队的战斗力与部队的兵力成正比.但当把一支部队分成若干个作战队伍时,这个部队的战斗力就会大大的增强. 一支部队的战斗力是可以通过以下两个规则计算出来的: 1.若一支作战队伍的兵力为N,则这