Problem L. Stock Trading Robot

题目连接:

http://www.codeforces.com/gym/100253

Description

CyberTrader is an all-in-one trading solution for investment banks, quantitative hedge funds and

proprietary trading groups. It has only one drawback it is not implemented yet.

You are working on implementing a simple algorithm to buy/sell shares. It should work as follows. Initially

a robot has d dollars and doesn't have any shares. The robot's behaviour is dened by two positive integer

numbers a and b, their role is explained below.

Starting from the second day, every day the robot analyzes a new share price comparing it with the

previous share price. If the price increases the robot buys shares it buys as many shares as it can but

not more than x. Actually, x is not a constant and depends on the number of consecutive increases: x = a

for the rst increase, x = 2a for two increases in a row, and so on, i.e. x = ka for k consecutive increases.

Surely, the robot can buy only non-negative integer number of shares and the number depends on the

money it has and on x.

If the price decreases the robot sells shares it sells as many shares as it has but not more than y.

Actually, y is not a constant and depends on the number of consecutive decreases: y = b for the rst

decrease in a row, y = 2b for two decreases in a row, and so on, i.e. y = kb for k consecutive decreases.

If the price doesn't change the robot does not buy or sell any shares.

Write a program for the robot to simulate the above algorithm.

Input

The rst line of the input contains four positive integers n, d, a and b (1 ≤ n, d ≤ 105

, 1 ≤ a, b ≤ 10),

where n is the number of days to simulate the algorithm. The following line contains sequence of positive

integers p1, p2, . . . , pn (1 ≤ pi ≤ 105

), where pi

is the share price on the i-th day.

It is guaranteed that there will be no overow of the 32-bit signed integer type, so feel free to use type

int (in C++ or Java) to store the number of dollars and shares.

Output

Print the number of dollars and the number of shares the robot will have after n days.

Sample Input

5 10 1 2

1 2 3 4 5

Sample Output

2 3

Hint

题意

自动炒股机器人,在什么价格的时候,会自动买,然后自动卖。

题面给你说买的条件,和卖的条件。

题解:

模拟就好了……

代码

#include <bits/stdc++.h>

using namespace std;

const int N=100010;
int n,a,b,d,p[N]; int main()
{
scanf("%d%d%d%d",&n,&d,&a,&b);
for(int i=0;i<n;i++)
scanf("%d",&p[i]);
int cnt1=0,cnt2=0;
long long ans1=1LL*d,ans2=0;
for(int i=1;i<n;i++)
{
if(p[i]>p[i-1])
{
cnt1++;cnt2=0;
long long tmp=min(1LL*cnt1*a,ans1/p[i]);
ans1-=tmp*p[i];
ans2+=tmp;
}
else
if(p[i]<p[i-1])
{
cnt2++;cnt1=0;
long long tmp=min(1LL*cnt2*b,ans2);
ans1+=tmp*p[i];
ans2-=tmp;
}
else cnt1=0,cnt2=0;
}
cout<<ans1<<" "<<ans2<<endl;
return 0;
}

2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. 20155218 2006-2007-2 《Java程序设计》第5周学习总结

    20155218 2006-2007-2 <Java程序设计>第5周学习总结 教材学习内容总结 java中的错误都会被包装成对象,且是可抛出的. 通常称错误处理为异常处理,程序设计本身的错 ...

  2. 第6月第10天 svn checkout sqlite3

    1. http://www.cnblogs.com/xuling/p/5602036.html 2. http://blog.csdn.net/qq_26819733/article/details/ ...

  3. Android学习笔记——从源码看Handler的处理机制

    可能是出于性能的考虑,Android的UI操作是非线程安全的. 也就是说,如果你在一个新开的线程中直接操作UI是会引发异常的. 但是,Android又规定,不要去阻塞UI线程!否则,轻者引起程序卡顿, ...

  4. 灵活、可高度自定义的——Progress进度圈、弹窗、加载进度、小菊花

    DDProgressHUD的介绍 提供了四种类型的展示: 显示无限旋转的加载图(比如小菊花,可以自定义),显示文字信息.网络刷新时经常用到. 显示加载进度的动画,也可以显示文字.网络下载时用的比较多, ...

  5. 『实践』Yalmip+Ipopt+Cplex使用手册

    Yalmip+Ipopt+Cplex使用手册 1.软件版本 Cplex 12.6.2,Matlab R2014a,Ipopt 3.12.9,Yalmip 2.Cplex添加方法 官方下载地址: htt ...

  6. H5页面关于android软键盘弹出顶起底部元素的解决方案

    应用场景:用div在移动端页面设置一个底部工具栏,css的代码大概如下: .tool{ width: 100%; height: 60px; position: fixed; left: 0px; b ...

  7. Python学习五|集合、布尔、字符串的一些特点

    #集合本身就像无值的字典 list1 = set([1,2,3,4]) list2 = {1,2,3,4} print('list1 == list2?:',list1==list2)#list1 = ...

  8. ubuntu12.04安装maven

    step: 1,确认已经安装jdk, java --version 2,下载apache-maven-3.3.9 下载地址:http://maven.apache.org/download.cgi 3 ...

  9. java实战

    1.http://learning.happymmall.com/ http://www.happymmall.com/index.html  前台官网 http://test.happymmall. ...

  10. 移动网络简介与RRC

    1.移动网络简介 1G:表示第一代移动通讯技术,以模拟技术为基础的蜂窝无线电话系统,如现在已经淘汰的模拟移动网.1G无线系统在设计上只能传输语音流量,并受到网络容量的限制. 2G:第二代手机通信技术规 ...