hiho 1604 - 股票价格,思维题
题目大意
小Hi最近在关注股票,为了计算股票可能的盈利,他获取了一只股票最近N天的价格A1~AN。
在小Hi的策略中,每天可以在下列三种操作中选取一种:
1.什么也不做;
2.按照当天的价格买进一个单位的股票;
3.按照当天的价格卖出部分或所有股票。
现在小Hi希望能够知道,如果在N天前手中持有的股票数为0,并且假设拥有无限的金钱,在这N天结束能够获得的最大利润是多少?
第一行包含一个整数N。
第二行包含N个整数,A1, A2, ... AN。
对于30%的数据, 1 ≤ N ≤ 103
对于100%的数据,1 ≤ N ≤ 106, 1 ≤ Ai ≤ 100
----------------------------------------------------------------------------------------------------------------------------
画下折线图就明白了,从后向前找,如果小于当前股票值 ans+=差值,这就是利润
#include <cstdio>
#include <iostream>
#include <algorithm> using namespace std;
typedef long long LL;
const int N = 1000100;
int A[N]; int main(){
int n; cin>>n; int ans = 0;
for(int i=0;i<n;i++) scanf("%d",A+i);
for(int i=n-1;i>=0;){
int j=i-1;
for(;j>=0;j--){
if(A[j]<A[i]) ans+=A[i]-A[j];
else break;
}
i = j;
}
printf("%d\n",ans);
return 0;
}
hiho 1604 - 股票价格,思维题的更多相关文章
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- cf796c 树形,思维题
一开始以为是个树形dp,特地去学了..结果是个思维题 /* 树结构,设最大点权值为Max,则答案必在在区间[Max,Max+2] 证明ans <= Max+2 任取一个点作为根节点,那么去掉这个 ...
随机推荐
- C#中网络通信
一.服务端代码 using System; using System.Collections.Generic; using System.Linq; using System.Net; using S ...
- ubuntu 14.04开机出现错误“Error found when loading /root/.profile”解决
在刚修改完root权限自动登录后,发现开机出现以下提示: Error found when loading /root/.profile stdin:is not a tty ………… 解决方法:在终 ...
- 纯css实现宽度自适应,高度与宽度成比例
html: <div></div> css div{ width: 33.33%; box-sizing: border-box; float: left; position: ...
- Pyhton学习——Day37
# HTML# import socket## def main():# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)# sock. ...
- 用 Java 技术创建 RESTful Web (服务 JAX-RS:一种更为简单、可移植性更好的替代方式)
作者: Dustin Amrhein, 软件工程师, IBM Nick Gallardo, 软件工程师, IBM 出处: http://www.ibm.com/developerworks/cn/we ...
- NuSOAP笔记:如何创建复杂数据类型
PHP已经有了内置的SOAP扩展,但是它不具备自动生成WSDL的能力,所以很多时候,NuSOAP还是有一定诱惑力的. 在应用稍微复杂点的时候,单靠integer, string等简单数据类型是不能满足 ...
- BeanUtils(前端赋值给后台,忽略空属性)
package com.drn.core.util; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; im ...
- 【codeforces 190C】STL
[题目链接]:http://codeforces.com/problemset/problem/190/C [题意] 让你根据去掉标点符号的; pair 以及 int这两种类型; 确定出一种类型; 使 ...
- C#WIFI搜索与连接
1.功能搜索WIFI并连接 2.所用工具及资源:VS2012 Managed Wifi API(即:引用ManagedWifi.dll文件地址:http://files.cnblogs.com/fil ...
- Informatica PowerCenter使用介绍-转载
转载自:https://blog.csdn.net/wen_demon/article/details/44155639 1. INFORMATICA CLIENT的使用1.1 Repository ...