ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker
Gina Reed, the famous stockbroker, is having a slow day at work, and between rounds of solitaire she is day-dreaming. 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 RollercoasterInc. The total number of shares in Rollercoaster Inc. is 100 000, so Gina can not own more than100 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 2322^{32}232.
样例输入
6
100
200
100
150
125
300
样例输出
650
这题卡了我好久,还是代码的问题,以为自己实现了,其实自己没有实现。
题意:给出天数与每一天股份的价格,开局100元,其他全靠炒。输出最后最多能得到多少钱。
解题思路:每一天无非就三种状态,不操作,全买,全卖。
如果后面股票价格会上升,那么当前就应该全买,反之,当天就全卖。
(但要注意股市只有10w股,当你把10w股全买完时,就不能再买了)
我的写法是遍历一遍,在每个上升的序列中,选最小的那个买,最大的那个卖。
附ac代码:
1 #include <cstdio>
2 #include <cstring>
3 #include <iostream>
4 #include <algorithm>
5 #define ll unsigned long long
6 using namespace std;
7 ll day[370];
8 const ll mm = 100000;
9 int main() {
10 ios::sync_with_stdio(false);
11 int n;
12 ll cnt = 0;
13 ll my = 100;
14 cin>>n;
15 for(int i = 1; i <= n; i++) {
16 cin>>day[i];
17 }
18 int flag = 0;
19 for(int i = 1; i <= n; i++) {
20 if(day[i] < day[i+1] && my >= day[i] && flag == 0) {
21 flag = 1;
22 cnt = min(my / day[i],mm);
23 my -= cnt * day[i];
24 // cout<<my<<endl;
25 }
26 if(day[i] > day[i+1]) {
27 flag = 0;
28 my += cnt*day[i];
29 cnt = 0;
30 // cout<<my<<endl;
31 }
32 }
33 cout<<my<<endl;
34
35 }
最新文章
- Xamarin.Forms 简介
- 设置statusBarStyle
- Python+Selenium进行UI自动化测试项目中,常用的小技巧3:写入excel表(python,xlsxwriter)
- 5332盛照宗 如何获取新技能+c语言学习调查
- 关于 swift 的图片多选问题
- 移动应用(手机应用)开发IM聊天程序解决方案
- 用Python进行语音信号处理
- dt dd 如何在同一行上
- div整体布局分析
- [转]mysql慢查询日志
- .Net Core Session验证码
- Web爬去的C#请求发送
- 洛谷【P2393】题解
- MyEclipse解决SVN同步冲突问题conflict in the working copy obstructs the current operation
- 终于理解kalman滤波
- Sequel自动生成Select语句
- C#/VB.NET 操作Word批注(二)——如何插入图片、读取、回复Word批注内容
- Ubuntu更新源问题终于解决了
- 阿里云部署Web项目
- android 内存泄漏,以及检测方法