编程介的小学生 2018-12-04 17:51 采纳率: 20.5%
浏览 432
已采纳

求教下,这个问题的C语言的解法是什么呢???

Problem Description
After a lucrative enterprise (the details of which are best left untold) a large gold bar has come into your possession. However, since you promised your accomplices a share of the loot, you will need to split it up into several pieces.

Dividing a gold bar is not an easy task. Fortunately, you've found a goldsmith willing to do it without asking questions, under the conditions that he can keep a fixed percentage of the bar being divided as payment for his labour, and he will only divide it into two parts (although they don't have to be equal halves; you can pick the ratio).

For example, suppose you have a 100 gram gold bar, you have promised your two accom- plices a share of 15 and 21 gram respectively and the goldsmith asks a 10% fee for each split. You can then first split the bar at a ratio of 5:4, yielding a 50 gram part (which you keep) and a 40 gram piece, which you split at 5:7 to yield the 15 and 21 gram pieces for your accomplices. Note that at each cut, you lose 10% of the gold to the goldsmith.

Since you want to maximize your own share of the loot without being unfair to your accomplices, you must be careful in the way you divide up the gold. In the example, if you had started by cutting off a 15 gram piece first, and then a 21 gram piece off the remaining bar, you would have ended up with only a 46.5 gram piece for yourself.

Your task is to determine how much gold you can keep, if you make the right cuts!

Input
On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

A line with three integers: the weight of the gold bar w (1 <= w <= 1 000 000), the cutting fee as a percentage p (0 <= p < 100), and the number of accomplices n (1 <= n <= 50).

n lines, each with the integer share s (1 <= s <= w) you promised an accomplice.

Output
For each test case:

One line with the maximum amount of gold you can keep to yourself, or -1 if it is impossible to divide the gold satisfying the requirements.

Note that the answer is not always an integer. Your answer should have either an absolute or a relative error of at most 10-4.

Notes Your accomplices don't mind if you give them more gold than they bargained for. See the second sample case for a situation in which this is inevitable.

Sample Input
3
100 10 2
15
21
45 15 3
11
11
11
50 0 3
10
20
25

Sample Output
50
0
-1

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-03-28 10:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?