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 矩阵
python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入numpy的包. 1.numpy的导入和使用 from numpy import *;#导入numpy的库函数 im ...
- 安装linux系统-CentOS-6.8-x86_64-minimal.iso
1: 2: 3:单击[Next]继续安装. 4:安装语言,选择[Chinese(Simplified)(中文(简体))]菜单,单击[Next]继续. 5:系统键盘,选择[美国英语式]菜单,单击[下一步 ...
- 学习MAP 地图好地址
http://www.cnblogs.com/beniao/archive/2010/01/13/1646446.html Bēniaǒ成长笔记在IT江湖里我不是一名老手,我只是一名普通的程序员,愿意 ...
- 2010–2011, NEERC, Northern Subregional C.Commuting Functions
C.Commuting Functions 由于要求答案字典序最小,我们肯定希望从g(1)开始对函数g进行赋值,于是又公式f(g(x))=g(f(x)) 设f(x)=i 我们推导出 由于f是双射,当i ...
- Nginx配置try_files实践二
本文内容承接<Nginx配置try_files实践一> 1. 环境: OS:Ubuntu 15.10 nginx:nginx/1.9.3 (Ubuntu) 假设有三台虚拟机db1(IP:1 ...
- P3402 【模板】可持久化并查集
传送门 //minamoto #include<bits/stdc++.h> using namespace std; #define getc() (p1==p2&&(p ...
- sql 索引详解
索引的重要性 数据库性能优化中索引绝对是一个重量级的因素,可以说,索引使用不当,其它优化措施将毫无意义. 聚簇索引(Clustered Index)和非聚簇索引 (Non- Clustered Ind ...
- 【杂文】5亿大质数表(5e8)
[杂文]\(5\) 亿大质数表(\(5e8\)) 在写哈希,刷数论题时曾一度想要查质数,\(F**k\) 百度文库数据又少,翻页蛋疼,还不给复制,真的是服了. 于是在我闲的蛋疼的时候就搞了个质数表出来 ...
- 【css】回想下经典的布局
看到这张图相信大多数人都很熟悉,这曾经是一种经典的布局方式,一道经典的面试题,一般形如"实现一个布局,左右固定宽度,中间自适应".随着岁月的流转,时光的交替(颇有一种“天下风云出我 ...
- 题解报告:poj 3468 A Simple Problem with Integers(线段树区间修改+lazy懒标记or树状数组)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...