zoukankan      html  css  js  c++  java
  • Daydreaming Stockbroker----Gym

    http://codeforces.com/gym/101550/attachments

     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 .

    Sample Input 1

    6

    100

    200

    100

    150

    125

    300

    Sample Output 1

    650

    看对题目就对一半了,模拟题,有了正确的思路,再就是注意一些细节上的处理,这道题A就完了

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 long long min(long long x, long long y)
     5 {
     6     if(x<y) return x;
     7     else return y;
     8 }
     9 
    10 int main()
    11 {
    12     long long n, i, j, sum, mon;
    13     long long a[400];
    14     scanf("%lld", &n);
    15     for(i=0; i<n; i++)
    16     {
    17         scanf("%lld", &a[i]);
    18     }
    19     sum = 0;
    20     mon = 100;
    21     for(i=0; i<n; i++)
    22     {
    23         for(j=i; j<n; j++)
    24         {
    25             if(j==n-1||a[j+1] > a[j]) break;
    26         }
    27         i = j;
    28         if(a[j]<=100) break;
    29     }
    30     if(i>=n) printf("100
    ");
    31     else
    32     {
    33         long long flag = 1;
    34         sum = mon / a[i];
    35         mon %= a[i];
    36         for(; i<n; i++)
    37         {
    38             if(flag==1||sum)
    39             {
    40                 for(j=i; j<n; j++)
    41                 {
    42                     if(j==n-1||a[j+1] < a[j]) break;
    43                 }
    44                 mon = mon + sum * a[j];
    45                 sum = 0;
    46                 flag = 0;
    47             }
    48             else
    49             {
    50                 for(j=i; j<n; j++)
    51                 {
    52                     if(j==n-1||a[j+1] > a[j]) break;
    53                 }
    54                 if(j==n-1) break;
    55                 sum = min(100000, sum + mon / a[j]);
    56                 mon = mon - sum * a[j];
    57                 flag=1;
    58             }
    59             i = j;
    60         }
    61         printf("%lld
    ", mon);
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    JAVA联调接口跨域解决办法
    Quartz集成springMVC 的方案二(持久化任务、集群和分布式)
    Quartz集成springMVC 的方案一
    Java 常调用的Webservice接口的方法
    集成Dubbo服务(Spring)
    Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
    事务的隔离级别 数据库
    Spring 之注解事务 @Transactional
    Request To JavaBean(请求对象转换为JavaBean对象)
    springmvc+mongodb+maven 项目搭建配置
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11451558.html
Copyright © 2011-2022 走看看