FZU 2278 概率

题目分析:http://acm.fzu.edu.cn/problem.php?pid=2278

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     public static void main(String[] args) {
 6         Scanner sc=new Scanner(System.in);
 7         int T=sc.nextInt();
 8         int []a = new int[2010];
 9         int cnt=0;
10         while (T>0)
11         {
12             int n=sc.nextInt();
13             int m=sc.nextInt();
14             BigInteger ans=BigInteger.valueOf(m);
15             BigInteger card=BigInteger.valueOf(0);
16             for (int i = 0; i < n; i++) a[i] = sc.nextInt();
17             for (int i = 0; i < n; i++)
18             {
19                 if (a[i+1]>a[i])
20                 {
21                     card = card.add(ans.divide(BigInteger.valueOf(a[i])));
22                     ans = ans.mod(BigInteger.valueOf(a[i]));
23                 }
24                 else
25                 {
26                     ans = ans.add(card.multiply(BigInteger.valueOf(a[i])));
27                     card = BigInteger.valueOf(0);
28                 }
29             }
30             System.out.printf("Case #%d: ",++cnt);
31             System.out.println(ans.mod(BigInteger.valueOf(1000000007)));
32             T--;
33         }
34     }
35 }

 

posted on 2017-08-02 19:27  poler  阅读(251)  评论(0编辑  收藏  举报

导航