-->
当前位置:首页 > 题库

PROGRAMMING:Pirates share the spoils

Luz5年前 (2021-05-10)题库353
P pirates stole D diamonds and then went to the high seas to share the spoils. They agreed on the following strategies:
First, P pirates decide the serial number of 1 - P by drawing lots. Then, pirate No. 1 puts forward a distribution scheme (the scheme should give the specific number of each pirate). If the absolute majority (i.e. more than half) including pirate No. 1 agrees, the distribution scheme will be implemented, otherwise, pirate No. 1 will be put into the sea to feed sharks; Then, similarly, pirate No. 2, pirate No. 3 and so on put forward the plan in turn until the plan that can obtain the absolute majority agreement appears, or only the last pirate is left, who monopolizes all the diamonds. Please write a program to give the number of diamonds in the diamond distribution plan of pirate No. 1.
Three assumptions are attached
-"Smart" and "greedy" hypothesis: every pirate can always take the maximum of his own interests as the code of conduct;
-"Humanized" assumption: pirates will not deliberately kill their accomplices if they can get as many diamonds as possible;
-"Unbiased" assumption: there is no personal grudge between pirates, and the order of diamonds allocated to other pirates is based on the priority of small serial numbers.
###Input format:
Enter two positive integers D and P in one line (3 $$$Le $$p $$$Le $$d $$$Le $$100).
###Output format:
Output the number of diamonds in pirate 1's diamond distribution plan.
###Input example:
```in
10 7
```
###Output example:
```out
six
```







answer:If there is no answer, please comment