您现在的位置:首页 > >

D. Daydreaming Stockbroker

发布时间:





Daydreaming Stockbroker
?



问答









  • ?1000ms
  • ?65536K



    Gina Reed, the famous stockbroker, is having a slow day at work, and between rounds of solitaire she is day-dreaming. 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 RollercoasterInc. The total number of shares in Rollercoaster Inc. is?100 000, so Gina can not own more than100 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}2?32??.?








    样例输入

    6
    100
    200
    100
    150
    125
    300


    样例输出

    650













    智商已废 = =?




    感觉代码还挺漂亮 存下。


    ans记录当前总价值,s记录有多少个r价值的股票。每次升值的时候 ?,r升值,每次可以买更多股的时候 买更多股 。价格10万的限制就好 --?


    智商已废 - - ?找感觉ing




    贪心思路。。股票当然是越过股越好了 。因为如果卖的多的话就卖的更多 。


    然后总价值用ans记录 ?,刚刚好 股数就可以非常方便的计算出来 ,


    然后 升值的时候,把ans的差价升值上去。把股数不变,价值变高 ,然后 就动态起来了 = = 好神奇


    贪心思路出的动态规划吧



    #include
    #include
    #include
    #include
    using namespace std;
    int main()
    {
    long long n;
    while(cin>>n)
    {
    long long x,ans=100,s=0,r=100;
    for(long long i=0;i {
    cin>>x;
    if(x<=r)
    {
    s=ans/x;
    r=x;
    }
    if(s>100000) s=100000;
    if(x>r)
    {
    ans+=s*x-r*s;
    r=x;
    }
    //cout< }
    cout< }
    }














热文推荐
猜你喜欢
友情链接: 医学资料大全 农林牧渔 幼儿教育心得 小学教育 中学 高中 职业教育 成人教育 大学资料 求职职场 职场文档 总结汇报