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 ...
随机推荐
- hdu 4990 Reading comprehension(等比数列法)
题目链接:pid=4990" style="color:rgb(255,153,0); text-decoration:none; font-family:Arial; line- ...
- YTU 2629: E1 一种颜色,三个分量
2629: E1 一种颜色,三个分量 时间限制: 1 Sec 内存限制: 128 MB 提交: 300 解决: 226 题目描述 在计算机中,常用三种基色红(R).绿(G).蓝(B)的混合来表示颜 ...
- POJ1912 A highway and the seven dwarfs (判断凸包与直线相交 logn)
POJ1912 给定n个点 和若干条直线,判断对于一条直线,是否存在两个点在直线的两侧. 显然原命题等价于 凸包与直线是否相交. O(n)的算法是显而易见的 但是直线数量太多 就会复杂到O(n^2)由 ...
- mybatis中各种数据的映射类型
Mybatis对应的java和数据库的数据类型,最后有图片 Mybatis java ...
- bzoj 1707: [Usaco2007 Nov]tanning分配防晒霜【贪心||最大流(?)】
洛谷上能过的最大流bzoj上T了--但是贪心做法明明在洛谷上比最大流要慢啊--如果是最大流的话就是裸题了吧 说一下贪心,就按照防晒霜排序,然后对每一个防晒霜选一头可以使用的且r最小的牛 就,没了. 贪 ...
- bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】
仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...
- js 获取图片宽高 和 图片大小
获取要查看大小的img var img_url = 'http://img5.imgtn.bdimg.com/it/u=4267222417,1017407570&fm=200&gp= ...
- JD笔试
题目表述: 给定n道题目,以及每道题目答对的概率,问小明能及格的概率. 样例: 40 50 50 50 50 0.31250 思路: 递归枚举对的题目个数,最后TLE之过40%: 知道正确解法是DP, ...
- [译]The multi Interface
The multi Interfacemulti接口 The easy interface as described in detail in this document is a synchrono ...
- JS在即将离开当前页面(刷新或关闭)时触发事件
// onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发 window.onbeforeunload = function () { return /^\#\/ipinfo/.t ...