问题 L: An Invisible Hand - (2018年第二阶段个人训练赛第三场)
题目描述
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
Move: When at town i (i<N), move to town i+1.
Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for Ai yen (the currency of Japan) at town i (1≤i≤N), where Ai are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the travel: the sum of the number of apples bought and the number of apples sold during the whole travel, must be at most T. (Note that a single apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized. Here, the profit of the travel is the amount of money that is gained by selling apples, minus the amount of money that is spent on buying apples. Note that we are not interested in apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change Ai into another arbitrary non-negative integer Ai' for any town i, any number of times. The cost of performing this operation is |Ai−Ai'|. After performing this operation, different towns may have equal values of Ai.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi's expected profit is initially at least 1 yen.
Constraints
1≤N≤105
1≤Ai≤109 (1≤i≤N)
Ai are distinct.
2≤T≤109
In the initial state, Takahashi's expected profit is at least 1 yen.
输入
N T
A1 A2 … AN
输出
样例输入
3 2
100 50 200
样例输出
1
提示
In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:
1.Move from town 1 to town 2.
2.Buy one apple for 50 yen at town 2.
3.Move from town 2 to town 3.
4.Sell one apple for 200 yen at town 3.
If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1.
There are other ways to decrease Takahashi's expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.
em题目的意思就是说一个商人可以从一个地方买苹果,然后再下不知道几个地方卖出去,每个地方都有个苹果的价值(且不相等),他想取得最大的利润,(毕竟商人)。而另一个竞争对手想要阻止他,哪怕只令他少赚一块钱,他可以任意修改地方苹果售价,但是要付出相等的代价。求最小的代价。
那我们只需要求出第一个商人最大价值出现了几次(因为地方售价不相等,所以可以不会出现改一个地方售价影响两个最大价值的情况),然后改动他卖出或者出售地方售价就ok,毕竟求最小那么我们就只改动1就好 ,那么最小代价就变成了,最大利润出现的次数。
暴力跑肯定超时的,那么就在输入的时候算出来每个地方的利润,顺便记录最大值即可。
#include<iostream>
#include<math.h>
#include<cstdio> using namespace std; int dp[];
int main()
{
int n,t;
scanf("%d%d",&n,&t);
int minn = 0x3f3f3f3f;
int maxn = ;
for(int i=;i<n;i++)
{
int a;
scanf("%d",&a);
dp[i] = a - minn>=?a - minn:;
minn = min(a,minn);
maxn = max(dp[i],maxn);
}
int ans = ;
for(int i = ;i<n;i++)
{
if(maxn == dp[i])ans++;
}
printf("%d\n",ans);
}
问题 L: An Invisible Hand - (2018年第二阶段个人训练赛第三场)的更多相关文章
- 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...
- 2019年第二阶段我要变强个人训练赛第八场 B.序列(seq)
传送门 B.序列(seq) •题目描述 给出一个长度为n的序列a,每次对序列进行一下的某一个操作. •输入 第一行两个整数n,q表示序列长度和操作个数. 接下来一行n个数,表示序列a. 接下来q行表示 ...
- EZ 2018 03 09 NOIP2018 模拟赛(三)
最近挺久没写比赛类的blog了 链接:http://211.140.156.254:2333/contest/59 这次的题目主要考验的是爆搜+打表的能力 其实如果你上来就把所有题目都看过一次就可以知 ...
- UPC 2019年第二阶段我要变强个人训练赛第六场
传送门 A.上学路线 题目描述 小D从家到学校的道路结构是这样的:由n条东西走向和m条南北走向的道路构成了一个n*m的网格,每条道路都是单向通行的(只能从北向南,从西向东走). 已知小D的家在网格的左 ...
- 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...
- 2018牛客网暑假ACM多校训练赛(第三场)G Coloring Tree 计数,bfs
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-G.html 题目传送门 - 2018牛客多校赛第三场 G ...
- 2018牛客网暑假ACM多校训练赛(第三场)D Encrypted String Matching 多项式 FFT
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-D.html 题目传送门 - 2018牛客多校赛第三场 D ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
随机推荐
- Confluence 6 下载和安装 Oracle thin 驱动
基于许可证的考虑,我们不能将 Oracle 的驱动捆绑到 Confluence 中.如果你希望你的 Confluence 能够连接到 Oracle 数据库,你需要: 停止 Confluence. 进入 ...
- Java语法基础常见疑惑解答8,16,17,21图片补充
8. 16. 17. 21
- window 上安装 Scala
第一步:Java 设置 检测方法前文已说明,这里不再描述. 如果还为安装,可以参考我们的Java 开发环境配置. 接下来,我们可以从 Scala 官网地址 http://www.scala-lang. ...
- LabView(控件部分)
1.虚拟仪器的概述: 虚拟仪器是基于计算机的的仪器,计算机和仪器的密切结合是目前仪器的一个发展方向,大概有两种结合方式,一种是将计算机装入仪器中,实例就是只能化的仪器,流行的嵌入式系统的仪器,另一种就 ...
- 20165314 2016-2017-2 《Java程序设计》第9周学习总结
20165314 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 URl类 UDP数据报 广播数据报 套接字 套接字连接机制 代码托管
- Nginx详解十八:Nginx深度学习篇之Rewrite规则
Rewrite规则可以实现对url的重写,以及重定向 作用场景: 1.URL访问跳转,支持开发设计,如页面跳转,兼容性支持,展示效果等 2.SEO优化 3.维护:后台维护.流量转发等 4.安全 配置语 ...
- python操作注册表
#注册表操作 # -*- coding: utf-8 -*- import win32api import win32con #打开注册表:传主键化值,子键值,操作方法(win32con.KEY_AL ...
- Python面向对象 三大特性 综合案例+1(视频里的作业)
class Dog: # 在创建一个小狗实例的时候,给它设置几个属性 def __init__(self, name, age = 1): self.name = name self.age = ag ...
- Tensorflow生成唐诗和歌词(上)
整个工程使用的是Windows版pyCharm和tensorflow. 源码地址:https://github.com/Irvinglove/tensorflow_poems/tree/master ...
- 八卦一下Starlark语言
八卦一下Starlark语言 编译移植TensorFlow时用到Bazel这一构建工具,Bazel用Starlark语法来编写WORKSPACE/BUILD文件,它们是类似于Make中的makeifl ...