• 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题


    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;
    }
  • 相关阅读:
    quick cocos2d-x之CCRect
    quick cocos2d x场景切换的生命周期函数调用学习
    quick cocos2d x 手机(Android端)启动过程学习
    quick cocos 或者 Cocos2dx 项目下的Android.mk文件的学习
    Android 与 C++ 之间纠缠
    Android 相册图片选取+自定义裁剪方式(非系统裁剪)
    Docker项目demo
    mysql(五)--性能优化总结
    Docker--网络
    mysql(四)------Mysql中的锁
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5775358.html
Copyright © 2020-2023  润新知