题目:

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 贪心)的更多相关文章

  1. Urozero Autumn 2016. NCPC 2016

    A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...

  2. D - Daydreaming Stockbroker Gym - 101550D

    题目链接:http://codeforces.com/gym/101550/attachments 总的来说就是要: 极大值卖出,极小值买入, 再加上端点时的特判. 还有就是会有连续几天股票价格相同的 ...

  3. Nordic Collegiate Programming Contest (NCPC) 2016

    A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...

  4. NCPC 2016:简单题解

    A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量.(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可. (在线做法:http ...

  5. ACM ICPC 2017 Warmup Contest 1 D

    Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...

  6. HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  7. HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

    Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  9. 2016 ICPC Mid-Central USA Region J. Windy Path (贪心)

    比赛链接:2016 ICPC Mid-Central USA Region 题目链接:Windy Path Description Consider following along the path ...

随机推荐

  1. 李维对VCL理解的几个错误

    研读深入浅出VCL一书的时候,有不少地方被网友提出疑问,而且似乎是网友们正确.但这丝毫不动摇李维在大中华Delphi界的江湖地位,因为高手应该是对整个系统理解的高手,而不是对某一个疑问的高手.能花巨量 ...

  2. CPU上电时序详细分析

    首先是RTC电源,这部分电力是永远不关闭的,除非电池(纽扣电池)没电并且没接任何外部电源(比如电池和电源适配器). RTC用以保持机器内部时钟的运转和保证CMOS配置信息在断电的情况下不丢失:其次,在 ...

  3. BZOJ_3667_Rabin-Miller算法_Mille_Rabin+Pollard rho

    BZOJ_3667_Rabin-Miller算法_Mille_Rabin+Pollard rho Description Input 第一行:CAS,代表数据组数(不大于350),以下CAS行,每行一 ...

  4. IDEA中Spark读Hbase中的数据

    import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.io.ImmutableBytesWr ...

  5. node.js开发错误——DeprecationWarning: Mongoose: mpromise

    原文地址 使用mongoose进行数据库操作时,总是提示: (node:5684) DeprecationWarning: Mongoose: mpromise (mongoose's default ...

  6. bzoj 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【Floyd】

    弗洛伊德之后按序列加起来即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...

  7. 洛谷P3400 仓鼠窝(单调栈)

    P3400 仓鼠窝 题目描述 萌萌哒的Created equal是一只小仓鼠,小仓鼠自然有仓鼠窝啦. 仓鼠窝是一个由n*m个格子组成的行数为n.列数为m的矩阵.小仓鼠现在想要知道,这个矩阵中有多少个子 ...

  8. 04-Vue中的动画

    Vue中的动画 为什么要有动画:动画能够提高用户的体验,帮助用户更好的理解页面中的功能: -使用过渡类名 1.html <div id="app"> <input ...

  9. Windows平台下Oracle 11g R2监听文件日志过大,造成客户端无法连接的问题处理

    近期部署在生产环境的应用突然无法访问,查看应用日志发现无法获取数据库连接. SystemErr R Caused by: oracle.net.ns.NetException: The Network ...

  10. IIS 相关配置

    IIS 和 VS 安装顺序 正常情况是先装IIS,后装VS:这样就不会发生错误了,因为asp.net就可以注册写入到IIS中.如果先装VS,再装IIS,这样就会导致"访问IIS元数据库失败& ...