`
lilisalo
  • 浏览: 1111889 次
文章分类
社区版块
存档分类
最新评论

HDU/HDOJ 4038 2011成都赛区网络赛H题

 
阅读更多

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
然后在这个大的思路前提下,进行各种讨论
非常考察选手的模拟能力。
这个题的情况非常多。我是把数据分为了正数和负数来处理的。
中间要考虑负数的个数是奇数还是偶数
然后分开处理
细节就不多说啦,看代码吧
我的代码:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics