USACO 2018 February Contest, Silver

Problem 1. Rest Stops

Farmer John and his personal trainer Bessie are hiking up Mount Vancowver. For their purposes (and yours), the mountain can be represented as a long straight trail of length LL meters (1≤L≤1061≤L≤106). Farmer John will hike the trail at a constant travel rate of rFrF seconds per meter (1≤rF≤1061≤rF≤106). Since he is working on his stamina, he will not take any rest stops along the way.

Bessie, however, is allowed to take rest stops, where she might find some tasty grass. Of course, she cannot stop just anywhere! There are NN rest stops along the trail (1≤N≤1051≤N≤105); the ii-th stop is xixi meters from the start of the trail (0<xi<L0<xi<L) and has a tastiness value cici (1≤ci≤1061≤ci≤106). If Bessie rests at stop ii for tt seconds, she receives ci⋅tci⋅t tastiness units.

When not at a rest stop, Bessie will be hiking at a fixed travel rate of rBrB seconds per meter (1≤rB≤1061≤rB≤106). Since Bessie is young and fit, rBrB is strictly less than rFrF.

Bessie would like to maximize her consumption of tasty grass. But she is worried about Farmer John; she thinks that if at any point along the hike she is behind Farmer John on the trail, he might lose all motivation to continue!

Help Bessie find the maximum total tastiness units she can obtain while making sure that Farmer John completes the hike.

INPUT FORMAT (file reststops.in):

The first line of input contains four integers: LL, NN, rFrF, and rBrB. The next NN lines describe the rest stops. For each ii between 11and NN, the i+1i+1-st line contains two integers xixi and cici, describing the position of the ii-th rest stop and the tastiness of the grass there.

It is guaranteed that rF>rBrF>rB, and 0<x1<⋯<xN<L0<x1<⋯<xN<L. Note that rFrF and rBrB are given in seconds per meter!

OUTPUT FORMAT (file reststops.out):

A single integer: the maximum total tastiness units Bessie can obtain.

SAMPLE INPUT:

10 2 4 3
7 2
8 1

SAMPLE OUTPUT:

15

In this example, it is optimal for Bessie to stop for 77 seconds at the x=7x=7 rest stop (acquiring 1414 tastiness units) and then stop for an additional 11 second at the x=8x=8 rest stop (acquiring 11 more tastiness unit, for a total of 1515 tastiness units).

Problem credits: Dhruv Rohatgi

官方翻译:

Farmer John和他的私人教练Bessie正在徒步攀登温哥牛山。基于他们的目的(也是你的目的),这座山可以用一条长为LL米(1≤L≤1061≤L≤106)的长直路径表示。Farmer John会沿着这条路径以每米rFrF秒(1≤rF≤1061≤rF≤106)的固定速度攀登。由于他正在训练他的耐力,他在途中不会进行任何的休息。

然而Bessie可以在休息站休息,在那里她能够找到一些美味的嫩草。当然,她也不能在任何地方都休息!在路径上总共有NN个休息站(1≤N≤1051≤N≤105);第ii个休息站距离路径的起点xixi米(0<xi<L0<xi<L),美味值为cici(1≤ci≤1061≤ci≤106)。如果Bessie在休息站ii休息了tt秒,她能够得到ci⋅tci⋅t个美味单位。

不在休息站的时候,Bessie会以每米rBrB秒(1≤rB≤1061≤rB≤106)的固定速度攀登。由于Bessie年轻而健康,rBrB严格小于rFrF。

Bessie想要吃到最多的美味嫩草。然而她也担心Farmer John;她认为如果在任何时候她位于Farmer John身后,Farmer John可能就会失去前进的动力了!

帮助Bessie求出,在确保Farmer John能够完成登山的情况下,她能够获得的最多的美味单位。

输入格式(文件名:reststops.in):

输入的第一行包含四个整数:LL,NN,rFrF,以及rBrB。下面NN行描述了休息站。对于11至NN之间的每一个ii,第i+1i+1行包含了两个整数xixi和cici,描述了第ii个休息站的位置和那里的草的美味值。

输入保证rF>rBrF>rB,并且0<x1<⋯<xN<L0<x1<⋯<xN<L。注意rFrF和rBrB的单位为秒每米!

输出格式(文件名:reststops.out):

输出一个整数:Bessie可以获得的最多的美味单位。

输入样例:

10 2 4 3
7 2
8 1

输出样例:

15

在这个样例中,Bessie的最佳方案是在位于x=7x=7的休息站停留77秒(获得1414个美味单位),再在位于x=8x=8的休息站停留11秒(再获得11个美味单位,总共是1515个美味单位)。

供题:Dhruv Rohatgi

具体思路:

奶牛走到当前位置后面所有站中价值最大的站台时,就一直吃草,等人来后,继续向前走,重复上述步骤(很容易想到此思路)

注意:速度单位为秒每米,所以以米为循环变量,到达L时停止

最难处理的是怎样求当前位置后的站台中最大的那个位置,如果边走边求,n log n显然超时

所以必须先预处理出来,我们定义一个结构体,里面放了站台的位置,价值和后面中最大价值站台的升序号

用sort以位置为关键字排序,倒叙查找,定义一个maxcmp表示当前站台至最后站台中最大价值站台的序号,不断更新,存到之前站台的next中。

别忘了long long !!!

usaco提交格式需要用noip格式,下面代码中注释掉了:

#include<stdio.h>
#include<algorithm>
using namespace std;
struct edge{int pos,v,next;
}a[100100];
bool cmp(edge a,edge b)
{return a.pos<b.pos;
}
long long int ans,l,n,va,vb;
int main()
{freopen("reststops.in","r",stdin);freopen("reststops.out","w",stdout);scanf("%lld%lld%lld%lld",&l,&n,&va,&vb);for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i].pos,&a[i].v);sort(a+1,a+n+1,cmp);int maxcmp=0-1;for(int i=n;i>=1;i--){a[i].next=maxcmp;if(a[maxcmp].v<=a[i].v)maxcmp=i;}long long int t1=0,t2=0,now=maxcmp;for(int i=1;i<=l;i++){t1+=va;t2+=vb;if(i==a[now].pos){ans+=(t1-t2)*a[now].v;t1=t2;now=a[now].next;}}printf("%lld",ans);fclose(stdin);fclose(stdout);return 0;
}

USACO 2018 FEBURARY CONTEST :SILVER T1相关推荐

  1. USACO 2018 January Contest

    USACO 2018 January Contest 比赛链接 T1 MooTube 题目链接 题目大意:给定一个图,两个点之间的距离是他们路径上边权的最小值.给定一个起点,求距离大于等于K的点有几个 ...

  2. USACO 2012 January Contest, Silver Division Solution

    T1是一道构图然后跑最短路的题. T2是一道裸的dp 然而我看了以后觉得爆搜是一定可以过掉的== 于是我先来一发二进制枚举,然后two points 维护答案.. T3是一道神题 首先要分类讨论,然后 ...

  3. USACO 2018 February Contest, Silver-Rest Stops

    G: Rest Stops 时间限制: 1 Sec  内存限制: 128 MB 提交: 97  解决: 38 [提交][状态][讨论版][命题人:admin] 题目描述 Farmer John and ...

  4. 【双端队列广搜/搜索+图论】AcWing 2019.拖拉机 USACO 2012 March Contest Silver Division

    [题目描述] 干了一整天的活,农夫约翰完全忘记了他把拖拉机落在田地中央了. 他的奶牛非常调皮,决定对约翰来场恶作剧. 她们在田地的不同地方放了 NNN 捆干草,这样一来,约翰想要开走拖拉机就必须先移除 ...

  5. USACO 2018 January Contest Platinum A: Lifeguards 题解

    将所有的区间按左端点从小到大排序 我们处理那些被完全包含的区间,这些区间即使删除也不会使答案变坏 这样先删一波,如果发现这种小区间的个数多于k,就可以直接算答案了 否则我们要dp 设dp[i][j]为 ...

  6. USACO 1月 2021-2022 January Contest Silver银组 题解

    你好啊我又又又来了 要准备usaco的铁铁们可以参考这个文章哦! 想刷好USACO--看这篇文章就够了_GeekAlice的博客-CSDN博客我最近是发现了一个很好用的网站https://blog.c ...

  7. Promotion Counting【USACO 2016 January Contest, Bronze】

    今天来分享一下我做过的几道Usaco的比较简单的题,Usaco是美国的一个c++竞赛比赛,但是全球各地的人都可以参加,Usaco没有监考,全凭诚信,但是你拿着这个 作弊 借鉴来的成绩,所有美国的大学都 ...

  8. BSOJ4217 【USACO 2013 Feburary Gold】旅行线路 DP(双路递推)

    4217 -- [USACO 2013 Feburary Gold]旅行线路 Description 贝西经营着一家旅行社,一天贝西带着几队游客沿着亚马逊河旅行,河的两边分布着一些景点,每个景点都对应 ...

  9. USACO 2020 February Contest, Gold

    USACO 2020 February Contest, Gold 图片懒得上传了,如果影响阅读可以看个人公开笔记 另外就是之前接近一年没登陆,所以消息都没看到,抱歉了. 测试地址 Problem 1 ...

最新文章

  1. CentOS安装新版RabbitMQ解决Erlang 19.3版本依赖
  2. 考前自学系列·计算机组成原理·中央处理器知识点
  3. Ubuntu之Pycharm:Ubuntu系统内Pycharm安装的图文教程
  4. 有些时候,我们以为对的意见,往往在行家看来是比较幼稚之亲身经历
  5. 数据结构-树5-二叉搜索树
  6. 7 WM配置-主数据-定义拣配区(Picking Area)
  7. 使用WebStorm将项目部署到IIS
  8. 《OpenGL编程指南》一第3章 OpenGL绘制方式
  9. java面向对象的六大原则
  10. 空巢青年,“空巢”是选择还是无奈? | 数据告诉你
  11. Web 项目中,MySQL 最新驱动下载、及配置
  12. 安装GitHub安装步骤
  13. 深入浅出详解因子分析,附案例教学(全)
  14. 网页右下角3秒自动弹出悬浮在线客服代码
  15. SVN可视化管理工具
  16. 感谢CSDN编辑精心采访--将人文融入到科技产品中
  17. 聊聊测试工程师的核心能力模型
  18. 行测题数字推理技巧总结(简单精辟)
  19. iOS:xcode5 自定义模板
  20. 流利阅读 2019.2.2 Barbie will soon be 60—and is still going strong

热门文章

  1. iOS开发者账户密码修改流程
  2. 计算机编程常用的英语,100916计算机编程常用的英语
  3. c语言单片机程序设计例,51单片机C语言程序设计经典实例(第2版)
  4. 如何快速将多个文件夹下内容合并到一个文件夹下
  5. 般若堂--Spring Boot系列之参数校验
  6. 在oracle 中编写一个程序,用VC 开 发 基 于ORACLE 数 据 库 应 用 程 序 的 两 种 方 法...
  7. 创业之路 - 魏杰:下一个 10 年,将造就一批新富翁
  8. 定语从句--专升本语法
  9. [POI 2004]ZAW
  10. 游戏思考13:关于MMORPG游戏服务器的种类及作用(以后会同步更新github,持续更新系列,目前有20个服务器说明,22/10/20)