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

2
3 1
1 2 3
4 1
1 2 1 2

Sample Output

Case #1: 3
Case #2: 4
答案可以打到10^9000 上大数
题目大意:给出每天物品的单价和本金,问买卖若干次后资金最多为多少? 
解题思路:谷底买,山峰卖,用大数。 被这个大数模板安排了 ans%1e9+7 模的过程会爆int
然后就一直WA 后面改了板子才过的
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("DATA.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const int maxn = 1e5 + ;
const int MAXL = ;
const int MAXN = ;
const int DLEN = ;
class Big {
public:
int a[MAXL], len;
Big(const int b = ) {
int c, d = b;
len = ;
memset(a, , sizeof(a));
while(d > MAXN) {
c = d - (d / (MAXN + )) * (MAXN + );
d = d / (MAXN + );
a[len++] = c;
}
a[len++] = d;
}
Big(const char *s) {
int t, k, index, L;
memset(a, , sizeof(a));
L = strlen(s);
len = L / DLEN;
if(L % DLEN) len++;
index = ;
for(int i = L - ; i >= ; i -= DLEN) {
t = ;
k = i - DLEN + ;
if(k < ) k = ;
for(int j = k; j <= i; j++) t = t * + s[j] - '';
a[index++] = t;
}
}
Big operator/(const LL &b)const {
Big ret;
LL down = ;
for(int i = len - ; i >= ; i--) {
ret.a[i] = (a[i] + down * (MAXN + )) / b;
down = a[i] + down * (MAXN + ) - ret.a[i] * b;
}
ret.len = len;
while(ret.a[ret.len - ] == && ret.len > ) ret.len--;
return ret;
}
bool operator>(const Big &T)const {
int ln;
if(len > T.len) return true;
else if(len == T.len) {
ln = len - ;
while(a[ln] == T.a[ln] && ln >= ) ln--;
if(ln >= && a[ln] > T.a[ln]) return true;
else return false;
} else return false;
}
Big operator+(const Big &T)const {
Big t(*this);
int big = T.len > len ? T.len : len;
for(int i = ; i < big; i++) {
t.a[i] += T.a[i];
if(t.a[i] > MAXN) {
t.a[i + ]++;
t.a[i] -= MAXN + ;
}
}
if(t.a[big] != ) t.len = big + ;
else t.len = big;
return t;
}
Big operator-(const Big &T)const {
int big;
bool flag;
Big t1, t2;
if(*this > T) {
t1 = *this;
t2 = T;
flag = ;
} else {
t1 = T;
t2 = *this;
flag = ;
}
big = t1.len;
for(int i = ; i < big; i++) {
if(t1.a[i] < t2.a[i]) {
int j = i + ;
while(t1.a[j] == ) j++;
t1.a[j--]--;
while(j > i) t1.a[j--] += MAXN;
t1.a[i] += MAXN + - t2.a[i];
} else t1.a[i] -= t2.a[i];
}
t1.len = big;
while(t1.a[t1.len - ] == && t1.len > ) {
t1.len--;
big--;
}
if(flag) t1.a[big - ] = - t1.a[big - ];
return t1;
}
LL operator%(const int &b)const {
LL d = ;
for(int i = len - ; i >= ; i--) d = ((d * (MAXN + )) % b + a[i]) % b;
return d;
}
Big operator*(const Big &T) const {
Big ret;
int i, j, up, temp, temp1;
for(i = ; i < len; i++) {
up = ;
for(j = ; j < T.len; j++) {
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if(temp > MAXN) {
temp1 = temp - temp / (MAXN + ) * (MAXN + );
up = temp / (MAXN + );
ret.a[i + j] = temp1;
} else {
up = ;
ret.a[i + j] = temp;
}
}
if(up != ) ret.a[i + j] = up;
}
ret.len = i + j;
while(ret.a[ret.len - ] == && ret.len > ) ret.len--;
return ret;
}
void print() {
printf("%d", a[len - ]);
for(int i = len - ; i >= ; i--) printf("%04d", a[i]);
}
};
int t, n, m, a[maxn], f[maxn];
int main() {
int cas = ;
sf(t);
while(t--) {
scanf("%d%d", &n, &m);
Big ans = m, temp;
for (int i = ; i <= n ; i++) sf(a[i]);
int i = , j, k;
while(i <= n) {
for (j = i ; j + <= n ; j++) if (a[j + ] > a[j]) break;
if (j == n) break;
for (k = j + ; k + <= n ; k++) if (a[k + ] < a[k]) break;
i = k + ;
temp = ans / a[j];
ans = ans + temp * (a[k] - a[j]);
}
LL ans1 = ans % mod;
printf("Case #%d: %lld\n", cas++, ans1);
}
return ;
}

Trades FZU - 2281 (大数+贪心)的更多相关文章

  1. Trades FZU - 2281 (贪心)(JAVA)

    题目链接: J - Trades  FZU - 2281 题目大意: 开始有m个金币, 在接下来n天里, ACMeow可以花费ci金币去买一个物品, 也可以以ci的价格卖掉这个物品, 如果它有足够的金 ...

  2. FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)

    C Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Pra ...

  3. Problem 2278 YYS (FZU + java大数)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2278 题目: 题意: 有n种卡牌,每种卡牌被抽到的概率为1/n,求收齐所有卡牌的天数的期望. 思路: 易推得公 ...

  4. 2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)

    Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB DreamGrid has a nonnegative integer n . He ...

  5. JAVA大数贪心

    题意:01给出一个数n,现在要将它分为m个数,这m个数相加起来必须等于n,并且要使得这m个数的或值最小. 思路分析: 一个简单的贪心,从高位到低位,判断当前位可否为 1 ,若可以,则将所有的数的这一位 ...

  6. FZU 2233 ~APTX4869 贪心+并查集

    分析:http://blog.csdn.net/chenzhenyu123456/article/details/51308460 #include <cstdio> #include & ...

  7. FZU 2219【贪心】

    思路: 因为工人造完一个房子就死了,所以如果m<n则还需要n-m个工人. 最优的方案应该是耗时长的房子应该尽快建,而且最优的是越多的房子在建越好,也就是如果当前人数不到n,只派一个人去分裂. 解 ...

  8. ZOJ - 3987 - Numbers (大数 + 贪心)

    参考自:https://blog.csdn.net/u013534123/article/details/78484494 题意: 给出两个数字n,m,把n分成m份,使得以下最小 思路: 或运算只有0 ...

  9. FZU 2139——久违的月赛之二——————【贪心】

    久违的月赛之二 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Stat ...

随机推荐

  1. a链接传参的方法

    //获取分案编号 var hrefVal=window.location.href.split("?")[1]; //得到id=楼主 //console.log(hrefVal+& ...

  2. [转载]Java集合框架的常见面试题

    http://www.jfox.info/40-ge-java-ji-he-lei-mian-shi-ti-he-da-an 整理自上面链接: Java集合框架为Java编程语言的基础,也是Java面 ...

  3. 使用HTML5制作loading图

    昨天发了一篇使用HTML5 canvas写的时钟的文章,今天发一篇关于使用HTML5制作loading图的文章. <!DOCTYPE html> <html> <head ...

  4. 条款02:尽量以const,enum,inline替换#define

    一.概述 尽量少用预处理器——宏替换 二.细节 1. 关于宏替换之常量 旧版本:#define N 10; 新版本:const int n = 10; 比较:#define不被视为语言的一部分,记号名 ...

  5. Alphabetic Removals(模拟水题)

    You are given a string ss consisting of nn lowercase Latin letters. Polycarp wants to remove exactly ...

  6. CentOS 6安装thrift支持erlang开发

    早前,在我的博文thrift多平台安装介绍了如何在debian/ubuntu下面安装thrift,并支持erlang开发的.而在CentOS平台下,并没有成功安装.经过不断摸索,终于成功了,这篇博文就 ...

  7. 【Docker 命令】- start/stop/restart命令

    docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...

  8. pycharm/webstorm创建react项目

    1.安装nodejs 2.安装reactapp依赖:npm install -g create-react-app 在pycharm/webstorm中选择react

  9. Spring IOC原理简析

    所谓IoC, 就是一个用XML来定义生成对象的模式. 1.现有三个类,Human是接口,Chinese是一个实现类,American是另一个实现类. 2.获取以上对象采用工厂模式的用法如下: 创建一个 ...

  10. mysql学习之数据备份与恢复

    该文使用mysql5.5 centos6.5 64位(本人使用rpm安装mysql,数据库的安装目录默认) 一.数据备份注意事项 读锁问题:数据库(或者某个表)一旦进行读锁操作则影响数据库的写操作所以 ...