https://www.luogu.org/problem/P2968

题目描述

Bessie has entered a bobsled competition because she hopes her hefty weight will give her an advantage over the L meter course (2 <= L <= 1,000,000,000).
Bessie will push off the starting line at 1 meter per second, but her speed can change while she rides along the course. Near the middle of every meter Bessie travels, she can change her speed either by using gravity to accelerate by one meter per second or by braking to stay at the same speed or decrease her speed by one meter per second.
Naturally, Bessie must negotiate N (1 <= N <= 100,000) turns on the way down the hill. Turn i is located Ti meters from the course start (1 <= Ti <= L-1), and she must be enter the corner meter at a speed of at most Si meters per second (1 <= Si <= 1,000,000,000). Bessie can cross the finish line at any speed she likes.
Help Bessie learn the fastest speed she can attain without exceeding the speed limits on the turns.
贝茜从山顶滑雪到山脚,山顶到山脚距离是L(2<L<10^9)米.贝茜在起点的速度是1米每秒,但是他的速度是可以改变的,在每一米的速度可以是前一米的速度加1、减1,或者等于前一米的速度.在滑行的过程中,贝茜会遇到N<=100000)个转弯处,第i个转弯处位于距离出发Ti米处,为了安全,贝茜到达第i个转弯处的速度不能超过Si(1<Si<10^9)米 每秒.当然贝茜到达终点时的速度没有最大限制.请你计算贝茜在滑雪过程中最大的速度可以是多少?
 
 
Consider this course with the meter markers as integers and the turn speed limits in brackets (e.g., '[3]'):
| []
|---+---+---+---+---+---+---+
| \
Start +
\
+
\
+ +++ (finish)
\ /
[] +---+---+
[] Below is a chart of Bessie's speeds at the beginning of each meter length of the course:
Max:
Mtrs:
Spd: Her maximum speed was near the beginning of meter .

输入描述:

* Line 1: Two space-separated integers: L and N
* Lines 2..N+1: Line i+1 describes turn i with two space-separated integers: Ti and Si

输出描述:

* Line 1: A single integer, representing the maximum speed which Bessie can attain between the start and the finish line, inclusive.

输入


输出

 

100000的数据规模显然很难区间DP,于是我们考虑贪心。

这题的特性:速度变化量为±1或0。

对于每个拐角,经过它的速度的最大限制(既要小于题目给出的安全限制,又要确保后面的拐角能够顺利通过)。

知道这个之后,我们就可以从前往后模拟,计算出每两个拐角之间的速度最大值(不要忘了还有起点和终点),以及到达拐角时的速度。

计算最大速度值要用点脑子(自己试着推下,或参考代码)

 
 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const double PI=acos(-);
const int maxn=;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); int l,n,ans;
struct node
{
int dis;//限制点的坐标
int speed;//限制速度
}limit[maxn]; bool cmp(node a,node b)
{
return a.dis<b.dis;
} int main()
{
scanf("%d %d",&l,&n);
for(int i=;i<=n;i++)
{
scanf("%d %d",&limit[i].dis,&limit[i].speed);
}
sort(limit+,limit++n,cmp);//不知道数据是不是按距离输入的,保险起见排个序 for(int i=n;i>=;i--)//反着更新速度限制
{
limit[i-].speed=min(limit[i-].speed,limit[i].speed+limit[i].dis-limit[i-].dis);
}
ans=;//答案
int s=;//速度值
for(int i=;i<=n;i++)
{
int d1=limit[i].speed-s;
int d2=limit[i].dis-limit[i-].dis;
if(d1<d2)
{
ans=max(ans,limit[i].speed+(d2-d1)/);
s=limit[i].speed;
}
else
{
ans=max(ans,s+d2);
s+=d2;
}
}
//注意最后一段是可以一直加速的,别忘了再比较一次
s+=l-limit[n].dis;
ans=max(ans,s);
printf("%d\n",ans);
return ;
}
 
 
 
 
 
 

[USACO09DEC]雪橇Bobsledding(贪心)的更多相关文章

  1. Luogu P2970 [USACO09DEC]自私的放牧

    https://www.luogu.org/problemnew/show/P2970 P2970 [USACO09DEC]自私的放牧 题目描述 Each of Farmer John's N (1 ...

  2. 洛谷 P2970 [USACO09DEC]自私的放牧Selfish Grazing

    P2970 [USACO09DEC]自私的放牧Selfish Grazing 题目描述 Each of Farmer John's N (1 <= N <= 50,000) cows li ...

  3. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  4. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  9. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

随机推荐

  1. git修改已经push的commit message

    git中修改上一次提交的commit的message git commit --amend -m "你的新的注释" git push -f 多个commit https://www ...

  2. Day 1:线程与进程系列问题(一)

    一.进程与线程 进程:正在执行的程序称为一个线程,主要负责内存空间的划分. 线程:线程在一个进程中负责代码的执行,就是进程中的一个执行路径. 多线程:在一个进程中有多个线程同时在执行不同的任务(同时指 ...

  3. Bootstrap-模态框 modal.js

    参考网址:http://v3.bootcss.com/(能抄不写) 1.大模态框 图片效果图: 代码:(button的属性data-target对应的是具体模态框的class) <!-- Lar ...

  4. BZOJ [Cqoi2017] 小Q的棋盘

    题解:枚举最后在哪里停止,然后剩下的步数/2 也就是找最大深度 枚举终止位置算是一种思路吧 #include<iostream> #include<cstdio> #inclu ...

  5. ref与out区别

    ref与out   out.ref都是传递引用(内存地址),使用后都将改变原来参数的数值.   ref 当调用方法时,在方法中会对ref传入的参数数值进行改变,若使用ref参数,则方法定义和调用方法都 ...

  6. php对象:get_object_vars(), get_parent_class(),is_subclass_of(),interface_exists()

    get_object_vars():获得对象的属性,以关联数组形式返回 get_parent_class():获得对象的父类 is_subclass_of():判断对象是否某类(参数2)的子类实例出的 ...

  7. 加速软件源更新和安装 ubuntu 软件中心

    Linux mint 12 修改加速软件源更新和安装 ubuntu 软件中心 由于 linux mint 12 是基于 ubuntu 的,可以使用 ubuntu 的源(Ubuntu 11.10 代号 ...

  8. vue title悬停

    title 设置name="peo" title="" v-on:mouseenter="peoAndCarHover(item.signStatus ...

  9. 用Pandas Dataframe来抓取重构金融股票的各种业务&数据形态

    4. 如果计算各项股票指标时,或者处理业务流程时,上一篇的直观认知数据结构,怎样帮助开发者去好好操作,又同时避免计算错误的坑. 首先从上篇的数据结据,可以看出/设计出多少种业务和股票指标. A. 恒生 ...

  10. 股票数据的原始数据形态&数据驱动来设计金融股票业务场景

    1. 数据源 其实金融数据没大家想象的那麽复杂,只需要最原始状态的数据,保存到本地即可以. 那麽,怎样才是股票数据的原始状态呢.那就看看1920's年代的道氏理论,他是怎样计算道琼斯指数,那麽他采用的 ...