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

题意:一个人在滑雪的过程中可以每秒加速1m/s,也可以保持速度不变,还可以每秒减速1m/s。滑道长L米,有n个拐角,当人滑行到拐角i时,他的速度不能超过Si。问在整个滑行过程中,人的最大速度是多少。

分析:假设人可以一直加速,从前往后遍历每个区间,当到某个拐角时的速度大于这个拐角的最大速度时,就向前更新前面的点的最大速度。dp[i]表示在第i米时可以滑行的最大速度。

#include<stdio.h>
#include<string.h>
int main()
{int L, n, i, dp[1005];while(~scanf("%d%d",&L,&n)){int a, b;memset(dp, 0, sizeof(dp));for(i = 0; i < n; i++){scanf("%d%d",&a,&b);dp[a] = b;}int pos = 1, lim = 1;for(i = 0; i <= L; i++){if(dp[i] == 0) //不是拐角的地方一直加速dp[i] = lim;else{if(dp[i] > dp[i-1])dp[i] = dp[i-1] + 1;else{pos = i; //从当前位置向前更新while(dp[pos - 1] - dp[pos] > 1){dp[pos-1] = dp[pos] + 1;pos--;}}}lim = dp[i] + 1;}int mmax = 0;for(i = 0; i <= L; i++)if(dp[i] > mmax)mmax = dp[i];printf("%d\n",mmax);}return 0;
}

NYOJ 309 BOBSLEDDING(dp)相关推荐

  1. NYOJ 304 节能(DP)

    题目描述 Dr.Kong设计的机器人卡多越来越聪明.最近市政公司交给卡多一项任务,每天早晨5:00开始,它负责关掉ZK大道右侧上所有的路灯. 卡多每到早晨5:00准会在ZK大道上某盏路灯的旁边,然后他 ...

  2. 求三角形最大面积(DP)

    求三角形最大面积(DP) 在OJ上奇迹般WA了:WA:70. Why? #include <iostream> #include <string.h> using namesp ...

  3. LeetCode 编辑距离 II(DP)

    1. 题目 给你两个单词 s 和 t,请你计算出将 s 转换成 t 所使用的最少操作数. 你可以对一个单词进行如下两种操作: 删除一个字符 替换一个字符 注意: 不允许插入操作 题目保证有解 示例: ...

  4. LeetCode 1220. 统计元音字母序列的数目(DP)

    文章目录 1. 题目 2. 解题 1. 题目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: - 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i ...

  5. LeetCode 265. 粉刷房子 II(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成 k 种颜色中的一种,你需要粉刷所有的房子并且使其相邻的两个房子颜色不能相同. 当然,因为市场上不同颜色油 ...

  6. LeetCode 256. 粉刷房子(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成红色.蓝色或者绿色这三种颜色中的一种,你需要粉刷所有的房子并且使其与相邻的两个房子颜色不能相同. 当然,因 ...

  7. LeetCode 1223. 掷骰子模拟(DP)

    1. 题目 有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数. 不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始 ...

  8. LeetCode 1155. 掷骰子的N种方法(DP)

    1. 题目 这里有 d 个一样的骰子,每个骰子上都有 f 个面,分别标号为 1, 2, -, f. 我们约定:掷骰子的得到总点数为各骰子面朝上的数字的总和. 如果需要掷出的总点数为 target,请你 ...

  9. LeetCode 1139. 最大的以 1 为边界的正方形(DP)

    1. 题目 给你一个由若干 0 和 1 组成的二维网格 grid,请你找出边界全部由 1 组成的最大 正方形 子网格,并返回该子网格中的元素数量.如果不存在,则返回 0. 示例 1: 输入:grid ...

最新文章

  1. Android车载开发总结
  2. Visual Studio 2019连接自动的Sql Server开发版数据库(C#语言)
  3. 深层神经网络中的前向传播
  4. Java基础-IO流对象之数据流(DataOutputStream与DataInputStream)
  5. C++ Primer 5th笔记(chap 18 大型程序工具)使用命名空间成员
  6. MFC主线程使用WaitForSingleObject阻塞的问题
  7. 五个问答,告诉你阿里云对象存储如何助力钉钉战胜业务洪峰
  8. mock SpringMVC 测试控制器方法
  9. Type Writer Audio X for Mac(单声道到立体声转换插件)
  10. 各种不同服务器301重定向设置代码大全
  11. gimp图片编辑器_GIMP图像编辑器改变我生活的10种方式
  12. jmeter使用心得(一)
  13. 基于python及图像识别的围棋棋盘棋子识别1——定位棋盘位置
  14. 计算机本地网络给手机使用吗,电脑共享网络给手机用的方法步骤
  15. Jmeter(五)bayboy录制时弹窗“当前页面的脚本发生错误”解决办法
  16. php 百度第三方登录接口开发,PHP:通过MVC,实现第三方登录(百度)
  17. 李佳琦以特殊人才落户上海,“带货一哥”即将成为“新上海人”
  18. 支付宝app支付对接1
  19. 矩阵 的逆、 迹、 秩
  20. 联合省选2022游记

热门文章

  1. 二叉树链表结构表示法
  2. js进阶 9-14 js如何实现下拉列表多选移除
  3. C++的坑真的多吗?
  4. shell脚本游戏之:剪刀石头布
  5. Hive的HQL(2)
  6. Flash 最小化,帧速变慢的问题
  7. 重构授课班时间安排模块代码
  8. 应用Rational 工具简化基于J2EE的项目(二)启动项目
  9. 软件工程中的需求分析
  10. 如何零基础或者转行数据分析师?