第四届河南省程序设计大赛:BOBSLEDDING (贪心)

http://nyoj.top/problem/309

题目描述:

 

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 的路,有n个弯道,在每个弯道的速度不能超过v,

每个时间段可以选择加速或减速或速度不变,求能到达的最大速度。

解题思路:

可以选择一直加速,到达弯道后,如果速度低于要求,可以通过。

如果高于要求,把当前位置速度变成要求的速度,再把前一位置改变成减速状态,直到有足够的距离可以减速。

需要注意给出的弯道位置并不是按照升序排列。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1020
int c[N];
struct data{
	int x;
	int y;
}a[N];
int cmp(data a,data b){
	return a.x < b.x;
}
int main()
{
	int n,l,i,j,s,ans;
	while(scanf("%d%d" , &l, &n)!=EOF){
		for( i=1; i<=n; i++ )
			scanf("%d%d", &a[i].x, &a[i].y);
		s=1;
		i=1;
		sort(a , a+n , cmp);
		memset(c, 0 , sizeof(c));
		c[0] = 1;
		while(s <= l){
			c[s] = c[s-1] + 1;
			if(s == a[i].x){
				if(c[s] > a[i].y){
					j = s-1;
					c[s] = a[i].y;
					while(1){
						if(c[j] == c[j+1] + 1 || c[j] == c[j+1])
							break;
						c[j] = c[j+1] + 1;
						j--;
					}	
				}
				i++;
			}
			s++;
		}
		ans = 0;
		for(i=0; i<=l; i++)
			if(c[i] > ans)
				ans=c[i];
		printf("%d\n", ans);
	}
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值