Stone
Time Limit: 3000/2000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 130Accepted Submission(s): 26
Problem Description
Given an array of integers {xi}. Each time you can apply one of the following operations to the array:
1. Choose an integer x from the array, replace it with x+1.
2. Add a new integer 1 to the array.
Define p as the product of all integers in the set. i.e. p=x1*x2*x3*...
What's the maximum possible value of p after exactly M operations?
Input
First line is a integer T (T ≤ 100), the number of test cases.
The first line of each test case contains two integers N and M, the number of integers in the initial set, and the number of operations.
The second line is N integers xi initially in the set.
1 ≤ N ≤ 100000
0 ≤ M ≤ 10^18
-10000 ≤ xi ≤ 10000
Output
For each case, you should output “Case k: ” first, where k indicates the case number and counts from one. Then the maximum product mod 1000000007.
Sample Input
4
1 1
5
3 2
1 2 3
3 2
-1 2 3
3 1
-3 -3 -3
Sample Output
Case 1: 6
Case 2: 18
Case 3: 6
Case 4: -18
Source
这个题的思路很简单,就是尽量多的凑够3
然后在这个大的思路前提下,进行各种讨论
非常考察选手的模拟能力。
这个题的情况非常多。我是把数据分为了正数和负数来处理的。
中间要考虑负数的个数是奇数还是偶数
然后分开处理
细节就不多说啦,看代码吧
我的代码:
分享到:
相关推荐
收集的部分HDOJ杭电ACM题的代码 大牛勿下 全是基础供初级acmer使用
自己积累的部分杭电oj的(hdu)解题代码。。大家有空来看看。 基本上是自己写的哈。有错误之处请指教、
HDOJ,2011阿里巴巴程序设计公开赛的标程 题目位置:http://acm.hdu.edu.cn/vip/2011alibaba/index.php
杭电oj4405,一道简单的概率dp题目
杭电acm解题报告 详细解析2000-2099 适合acm初学者
ACM ICPC HDOJ1000
思路:这个题和HDU - 5703类似,其实就是拆数问题,一个数的拆法其实就是2^(N-1),具体证明过程可以直接搜刚才杭电那道题的题解,所以这道题其实就是让你算2^(N-1),但是题目给的N特别大, 可以达到10^100000,我们...
压缩包包含十份报告,已经通过验收,实验内容:交换机、生成树、静态路由、NAT等完全根据教材实验要求
离线OJ题库(HDU ZJU等,部分有答案),需联网。
一个十分简单的程序,能够ac杭电hdu的第2050题,无注释,简单明了
杭州电子科技大学hdoj1002,大整数相加问题
HDU的一题........HDU DP动态规
HDU ACM 2005第几天 C++ http://acm.hdu.edu.cn/listproblem.php?vol=11 2005题 第几天?
hdu 期末考试复习资料 计算机网络 编译原理 计算机图形学 编译原理 信息安全与技术 数据库应用系统开发
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
ACM HDU题目分类,我自己总结的大概只有十来个吧
ACM ICPC HDOJ 1005
杭电ACMhdu1163
HDU1059的代码
HDU 动态规划(46道题目