Accept: 94 Submit: 511
Time Limit: 1000 mSec Memory Limit : 262144 KB
Problem Description
This is a very easy problem.
ACMeow loves GTX1920. Now he has m RMB, but no GTX1920s. In the next n days, the unit price of GTX1920 in the ith day is Ci RMB. In other words, in the ith day, he can buy one GTX1920 with Ci RMB, or sell one GTX1920 to gain Ci RMB. He can buy or sell as many times as he wants in one day, but make sure that he has enough money for buying or enough GTX1920 for selling.
Now he wants to know, how many RMB can he get after the n days. Could you please help him?
It’s really easy, yeah?
Input
First line contains an integer T(1 ≤ T ≤20), represents there are T test cases.
For each test case: first line contains two integers n(1 ≤ n ≤2000) and m(0 ≤ m ≤1000000000). Following n integers in one line, the ith integer represents Ci(1 ≤ Ci ≤1000000000).
Output
For each test case, output "Case #X: Y" in a line (without quotes), where X is the case number starting from 1, and Y is the maximum number of RMB he can get mod 1000000007.
Sample Input
3 1
1 2 3
4 1
1 2 1 2
Sample Output
Case #2: 4
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院) 、import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args){
BigInteger[] a= new BigInteger[2010];
BigInteger[] b= new BigInteger[2010];
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int cas=0;
for (int k=0;k<t;k++)
{
cas++;
int n;
n=sc.nextInt();
BigInteger m=sc.nextBigInteger();
for (int i=1;i<=n;i++)
{
a[i]=sc.nextBigInteger();
}
int cnt=1;
for(int i=2;i<=n;i++)
{
if(a[cnt].compareTo(a[i])!=0)
{
++cnt;
a[cnt]=a[i];
}
}
a[cnt+1]=BigInteger.ZERO; //!!去重之后注意
int cmm=0;
b[1]=a[1];
cmm=2;
for(int i=2;i<=cnt;i++)
{
if(a[i].compareTo(a[i-1])>0&&a[i].compareTo(a[i+1])>0)
{
b[cmm++]=a[i];
}
else if (a[i].compareTo(a[i-1])<0&&a[i].compareTo(a[i+1])<0)
{
b[cmm++]=a[i];
}
}
int beg=1;
if(cmm>2&&b[1].compareTo(b[2])>0) beg=2;
for(int i=beg;i+1<cmm;i+=2)
{
BigInteger tmp=b[i+1].subtract(b[i]);
m=m.add(m.divide(b[i]).multiply(tmp));
}
m=m.mod(BigInteger.valueOf(1000000007));
System.out.println("Case #"+cas+": "+m);
}
}
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
#define MOD 1000000007
typedef unsigned long long ll;
const int MAXN = 1e5+10;
ll a[MAXN];
ll b[MAXN];
int main()
{
int t;
scanf("%d",&t);
int cas=0;
while(t--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
cas++;
int n;
ll m;
scanf("%d%llu",&n,&m);
int cnt=0;
for(int i=1;i<=n;i++)
{
scanf("%llu",&a[i]);
}
cnt=1;
for(int i=2;i<=n;i++)
{
if(a[cnt]!=a[i])
{
a[++cnt]=a[i];
}
}
a[cnt+1]=0; //!!!去重之后注意
int cmm=0;
b[1]=a[1];
cmm=2;
for(int i=2;i<=cnt;i++)
{
if(a[i]>a[i-1]&&a[i]>a[i+1])
{
b[cmm++]=a[i];
}
else if(a[i]<a[i-1]&&a[i]<a[i+1])
{
b[cmm++]=a[i];
}
}
int beg=1;
if(b[2]<b[1]) beg=2;
for(int i=beg;i+1<cmm;i+=2)
{
m=(m+((m/b[i])%MOD*((b[i+1]-b[i]))%MOD)%MOD)%MOD;
}
printf("Case #%d: ",cas);
printf("%llu\n",m%MOD);
}
return 0;
}