Daydreaming Stockbroker(2016 NCPC 贪心)
题目:
Gina Reed, the famous stockbroker, is having a slow day at work, and between rounds of solitaire she is daydreaming. Foretelling the future is hard, but imagine if you could just go back in time and use your knowledge of stock price history in order to maximize your profits! Now Gina starts to wonder: if she were to go back in time a few days and bring a measly ¥100 with her, how much money could she make by just buying and selling stock in Rollercoaster Inc. (the most volatile stock in existence) at the right times? Would she earn enough to retire comfortably in a mansion on Tenerife? Note that Gina can not buy fractional shares, she must buy whole shares in Rollercoaster Inc. The total number of shares in Rollercoaster Inc. is 100 000, so Gina can not own more than 100 000 shares at any time. In Gina’s daydream, the world is nice and simple: there are no fees for buying and selling stocks, stock prices change only once per day, and her trading does not influence the valuation of the stock.
Input:
The first line of input contains an integer d (1 ≤ d ≤ 365), the number of days that Gina goes back in time in her daydream. Then follow d lines, the i’th of which contains an integer pi (1 ≤ pi ≤ 500) giving the price at which Gina can buy or sell stock in Rollercoaster Inc. on day i. Days are ordered from oldest to newest.
Output:
Output the maximum possible amount of money Gina can have on the last day. Note that the answer may exceed 2 32 .
题意:
给出d天的股票价格,初始钱数为100,问通过买卖,最后一天能最多得多少钱(任何时候不能持有超过100000股股票)。
思路:
去重后处理出价格的谷峰和谷底,在价格谷峰出全部卖出,谷底出全部买进。
代码:
#include <bits/stdc++.h>
#define inf 1e9
#define FRE() freopen("in.txt","r",stdin)
using namespace std;
typedef long long ll;
const ll MOD = ;
const int maxn = ; int main()
{
//FRE();
int n;
ll a[maxn],buf[maxn],f[maxn];
memset(a,,sizeof(a));
memset(buf,,sizeof(buf));
memset(f,,sizeof(f));
cin>>n;
for(int i = ; i<=n; i++)
{
cin>>a[i];
}
int cnt = -;
buf[++cnt] = inf;
for(int i = ; i<=n; i++)
{
if(a[i]==a[i-])
continue;
buf[++cnt] = a[i];
}
buf[++cnt] = -;
// cout<<"cnt: "<<cnt<<endl;
// for(int i = 1; i<cnt; i++)
// {
// cout<<buf[i]<<" ";
// }
// cout<<endl;
for(int i = ; i<cnt; i++)
{
if(buf[i]<buf[i-] && buf[i]<buf[i+])
f[i] = -;
else if(buf[i]>buf[i-] && buf[i]>buf[i+])
f[i] = ;
}
ll money = ;
ll gu = ;
for(int i = ; i<cnt; i++)
{
if(f[i]==)//谷峰
{
money+=gu*buf[i];
gu = ;
}
else if(f[i]==-)//谷底
{
if(money/buf[i] > )
{
money = money-*buf[i];
gu = ;
}
else
{
gu+=money/buf[i];
money %= buf[i];
} }
}
cout<<money<<endl;
return ;
}
/*
Sample Input:
6
100
200
100
150
125
300
Sample Output:
650
*/
Daydreaming Stockbroker(2016 NCPC 贪心)的更多相关文章
- Urozero Autumn 2016. NCPC 2016
A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...
- D - Daydreaming Stockbroker Gym - 101550D
题目链接:http://codeforces.com/gym/101550/attachments 总的来说就是要: 极大值卖出,极小值买入, 再加上端点时的特判. 还有就是会有连续几天股票价格相同的 ...
- Nordic Collegiate Programming Contest (NCPC) 2016
A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...
- NCPC 2016:简单题解
A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量.(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可. (在线做法:http ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
- HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
Four Operations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 2016 acm香港网络赛 C题. Classrooms(贪心)
原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...
- 2016 ICPC Mid-Central USA Region J. Windy Path (贪心)
比赛链接:2016 ICPC Mid-Central USA Region 题目链接:Windy Path Description Consider following along the path ...
随机推荐
- python-----tuple用法
有一种有序列表叫元组:tuple.tuple和list非常类似,但是tuple一旦初始化就不能修改,比如同样是列出同学的名字: >>> classmates = ('Michael' ...
- 【高德地图API】绘制大地线 Geodesic/Great Circles
大地线(geodesic)是指地球椭球面上连接两点的最短程曲线. 大地线上每点的密切面(无限接近的3个点所构成的平面)都包含此点的曲面法线.因曲面法线互不相交,故为一条空间曲面曲线.在球面上,大圆弧( ...
- 25.EXTJS 主页面的jsp
1. /** * @author sux * @time 2011-1-11 * @desc main page */ var mainPage = Ext.extend(Ext.Viewport,{ ...
- ATX 学习 (三)-atxserver2-android-provider
服务端代码 代码clone到本地,搭好相应环境(怎么搭的这里就不介绍了,很好搭的哈)一般库首先查看main.py文件,debug模式开始运行 一开始就是没接触过的tornado.ioloop,有点偏底 ...
- Java多线程(三)SimpleDateFormat
多线程报错:java.lang.NumberFormatException: multiple points SimpleDateFormat是非线程安全的,在多线程情况下会有问题,在每个线程下得各自 ...
- Maven之项目搭建与第一个helloworld(多图)
这次记录第一个搭建一个maven的helloworld的过程. 转载 1.搭建web工程肯定得new 一个 maven工程,假如project中没有直接看到maven工程,那么选择Other,然后在W ...
- 242 Valid Anagram 有效的字母异位词
给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词.例如,s = "anagram",t = "nagaram",返回 true ...
- Storm编程入门API系列之Storm的可靠性的ACK消息确认机制
概念,见博客 Storm概念学习系列之storm的可靠性 什么业务场景需要storm可靠性的ACK确认机制? 答:想要保住数据不丢,或者保住数据总是被处理.即若没被处理的,得让我们知道. publi ...
- Linux 介绍快速浏览
Linux 介绍 内核 库: .so 共享对象,windows:dll 动态链接库 应用程序 Linux的基本原则:1.由目的单一的小程序组成:组合小程序完成复杂任务:2.一切皆文件:3.尽量避免捕获 ...
- MyElipse如何添加Emmet插件
把这个jar文件放到myeclipse2014安装目录下dropins文件夹中,然后重启myeclipse即可. 可到window-->perferences里查看,如果成功则会看到emmet选 ...