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}2​32​​.

样例输入

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 }


ACM ICPC 2017 Warmup Contest 1 D的更多相关文章

  1. ACM ICPC 2017 Warmup Contest 9 I

    I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...

  2. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  3. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  4. 2015-2016 ACM ICPC Baltic Selection Contest

    这是上礼拜三的训练赛,以前做过一次,这次仅剩B题没补.题目链接:https://vjudge.net/contest/153192#overview. A题,水题. C题,树形DP,其实是一个贪心问题 ...

  5. 2015-2016 ACM ICPC Baltic Selection Contest D - Journey(广搜)

  6. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  7. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  8. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  9. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

随机推荐

  1. 痞子衡嵌入式:MCUBootFlasher v3.0发布,为真实的产线操作场景而生

    -- 痞子衡维护的NXP-MCUBootFlasher工具(以前叫RT-Flash)距离上一个版本(v2.0.0)发布过去一年半以上了,这一次痞子衡为大家带来了全新版本v3.0.0,从这个版本开始,N ...

  2. nodejs内网穿透

    说明 本地服务注册,基于子域名->端口映射.公网测试请开启二级或三级域名泛解析 无心跳保活.无多线程并发处理 服务器端 请求ID基于全局变量,不支持PM2多进程开服务端.(多开请修改uid函数, ...

  3. floating point

    记录浮点数的单精度和双精度(IEEE754) 1.单精度(float) ​ 1.定义:单精度占4字节/32位,其中1号位符号位,其次是8位阶码/指数(阶符+阶数),23位尾数(小数). 2.双精度(d ...

  4. Java基础复习3

    循环的嵌套 public class demo8 {     public static void main(String[] args) {         /*  输出########       ...

  5. JavaScript中函数的调用!

    JavaScript中函数的调用! 1 普通函数 // 1 普通函数 function fn() { console.log(123); } // 函数名 + 一个小括号! 或者 函数名.call() ...

  6. Windows Server 2008 R2系统安装

    把系统U盘插到服务器上,然后启动服务器进入BIOS界面选择U盘启动. 根据服务器的不同,进入BIOS界面的按钮也不一样,主流的有F10.F11.F12.F2.ESC.delete等. 在从BIOS启动 ...

  7. FastAPI实践项目:SayHello(FastAPI + vue.js + axios + element ui)

    目录 简介 翻版 VS 本尊 后端服务 源码 接下来 简介 这次带来的是FastAPI + vue.js + axios + element ui (一个html文件里使用的) 实现的<Flas ...

  8. https://github.com/golang/go/wiki/CommonMistakes

    CommonMistakes https://golang.org/doc/faq#closures_and_goroutines Why is there no goroutine ID? ¶ Go ...

  9. “batteries included” philosophy

    https://docs.djangoproject.com/en/2.2/ref/contrib/ contrib packages Django aims to follow Python's & ...

  10. python3 安装 #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz RHEL 8 install Python 3 or Python 2 using yum 编译安装 python3.7.4 . OpenSSL 1.0.2 or 1.1. Consequently, OpenSSL 0.9.8 and 1.0

    #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz Modules/Setup.dist https://askubuntu ...