ZOJ 2536 best balance

Best Balance

Time Limit: 2 Seconds Memory Limit: 65536 KB

FatMouse has just got a baby! In order to control the baby's mouse weight, he bought a balance as well as some weights. By placing his baby on one side of the balance and some of the weights on the other, he could read how heavy his baby is. However, the baby is catching on weight so fast that FatMouse worries he would not be able to do that one day. Thus he has decided to purchase several other weights. He can choose how heavy these weights are. And of course he wants to maximize the smallest weight that this balance can not measure.

All weights are integers (in pounds). The balance can detect and compensate any fractional weight (less than one pound) difference between two sides. FatMouse never places any weight on the same side of his baby.

Input Description

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. T test cases follow, each preceded by a single blank line.

Each case starts with two integers n (0 <= n <= 20) and k (0 <= k <= 10), where n is the number of the weights that FatMouse currently has, and k is the number of weights that FatMouse is going to purchase. The next n integers ci (0 <= i < n, 1 <= ci < 100,000) give the weights (in pounds) he currently owns. Two consecutive numbers are separated by a single space.

Output Description

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

The output of each test case should be a single integer, which is the maximized smallest weight that he will not be able to measure.

Sample Input

4

3 1 1 2 4

3 2 1 3 5

2 1 1 1

3 0 1 2 5

Sample Output

Case 1:
16

Case 2:
24

Case 3:
6

Case 4:
4


Source: Asia 2005, Hangzhou (Mainland China), Preliminary

源码:
ZOJ <wbr>2536 <wbr>best <wbr>balance

解题报告:
这一道题主要要分析清楚一个问题:对于已经排好序的前n个数,如果能组合出1到S。则再加进一个数X,如果X大于S+1,则不能组合出为2*S+1这种情况。如果X小于S+1, 可以组合出1到S+X。
这一道题还要先对这n个数排序,sort函数会超时,用qsort。







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值