题目:

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. javax.servlet.http.Part 文件上传

    编辑jsp页面: <html> <head> <base href="<%=basePath%>"> <title>My ...

  2. ios29--多线程

    进程是指在系统中正在运行的一个应用程序(一个程序可以对应多个进程).每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内.比如同时打开迅雷.Xcode,系统就会分别启动2个进程.1个进程要 ...

  3. linux 基础 —— 网络管理

    Linux 最强大的功能是什么?网络功能. 修改 dns 服务器(解析域名到 ip 地址): $ sudo vim /etc/resolvconf/resolv.conf.d/base # 添加如下内 ...

  4. jquery plupload上传插件

    http://www.jianshu.com/p/047349275cd4 http://www.cnblogs.com/2050/p/3913184.html demo地址: http://chap ...

  5. 《Effective C++》笔记:III(转载)

    转自:http://www.cnblogs.com/destino74/p/3960802.html 条款5:Know what functions C++ silently writes and c ...

  6. bzoj1880: [Sdoi2009]Elaxia的路线(spfa,拓扑排序最长路)

    1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1944  Solved: 759[Submit][St ...

  7. weiphp插件开发注意

    插件命名要规范,插件名文件名,控制器名,模型名要以大写开头.不然的话会有惊喜!╮(╯▽╰)╭

  8. 解决前后端分离的“两次请求”引出的Web服务器跨域请求访问问题的解决方案

    在前后端分离的项目中,前端和后端可能是在不同的服务器上,也可以是Docker上,那就意味着前端请求后端Restful接口时,存在跨域情况. 后端在做了通用的跨域资源共享CORS设置后,前端在做ajax ...

  9. C#将类对象转换为字典

    主要是实现将类里面 的属性和对应的值转换为字典的键和值. public class RDfsedfw { /// <summary> /// 将匿名类转换为字典 /// </summ ...

  10. 全面学习ORACLE Scheduler特性(4)创建和管理Schedule

    三.使用Schedules 10g 中新推出的SCHEDULER可能确实会让很多初接触的朋友感觉晕头晕脑,相比之前的jobs,SCHEDULER中新增的概念太多.比如说jobs,仍然可以理解成之前版本 ...