zoukankan      html  css  js  c++  java
  • Trades FZU

    题目链接:

    J - Trades

     FZU - 2281 

    题目大意: 开始有m个金币, 在接下来n天里, ACMeow可以花费ci金币去买一个物品, 也可以以ci的价格卖掉这个物品, 如果它有足够的金币, 每天可以买或卖很多次; 求它在第n天能获得的最大金币数.。

    具体思路:相邻两个相比就可以了。保持每一天尽可能的拥有更多的金币。(题不难,主要是想存一java模板)

    AC代码:

     1 import java.util.*;
     2 import java.math.BigInteger;
     3 
     4 public class Main
     5 {
     6     public static void main(String[] args)
     7     {
     8         Scanner cin = new Scanner(System.in);
     9         BigInteger zero = new BigInteger("0");
    10         int T=cin.nextInt();
    11         for(int q=1; q<=T; q++)
    12         {
    13             int n=cin.nextInt();
    14             BigInteger have = new BigInteger("0");
    15             BigInteger m = cin.nextBigInteger();
    16             BigInteger pri[]=new BigInteger[2012];
    17             for(int i=0; i<n; i++)
    18             {
    19                 pri[i]=cin.nextBigInteger();
    20             }
    21             for(int i=0; i<n-1; i++)
    22             {
    23                 if(pri[i].compareTo(pri[i+1])<0)
    24                 {
    25                     m=m.add(pri[i+1].subtract(pri[i]).multiply(m.divide(pri[i])));
    26                 }
    27             }
    28             m=m.mod(new BigInteger("1000000007"));
    29             System.out.println("Case "+"#"+q+": "+m);
    30         }
    31     }
    32 }

     

  • 相关阅读:
    LCS LIS
    补个线段树
    洛谷1522
    AC自动机
    WF 2017 I
    WF2017 E
    最小生成树计数 基尔霍夫矩阵树定理
    bitonic tour luogu1523
    code+11月月赛
    模拟退火
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10727799.html
Copyright © 2011-2022 走看看