Three players, A, B, and C play a dice game, each player rolls two dice.
(The points of 2*3 = 6 dice should be set and stored in advance)
PART I:
Assume that each player can only see the points of his/her own two dice, simulate their game process.
Rules of PART I:
Starting from player A, the following steps are performed in turn.
First, the two dice thrown by the player A are output (indicating that A sees his/her dice), and then two numbers a and b are required to be input to represent A's guess for all dice, which means the number of b point dices in total is at least a.
Then it's the next player B's turn. After seeing his own dice, B can choose to enter 0 0 (two zeros) for "I don't believe" or to enter a new pair of numbers c and d, which means he/she guesses "there are at least c d points in all dice", where c,d must satisfy c≥a, and when c=a, d>b.
The game continues until someone input 0 0 (two zeros).
Optional rules:1 point dice can be regarded as any number of points.
For example:
O: A's turn: A has 2 and 1
I: 2 4
O: B's turn: B has 3 and 2
I: 2 3
O: Invalid input.
O: B's turn: B has 3 and 2
I: 3 2
O: C's turn: C has 2 and 5
I: 3 5
O: A's turn: A has 2 and 1
I: 4 2
O: B's turn: B has 3 and 2
I: 0 0
If someone (let's say player B above) enters 0 0 (two zeros), then show all 2 * 3 = 6 dice, determine the current player's "unbelieving" is right or wrong to judge the loser of the game: Assume that the previous player's input is x y. If the number of dice in y points is less than x (in a total of 6 dice), then the previous player (A) loses, otherwise, the current player (B) loses.
For example:
O: A's turn: A has 2 and 1
I: 2 4
O: B's turn: B has 3 and 2
I: 2 3
O: Invalid input.
O: B's turn: B has 3 and 2
I: 3 2
O: C's turn: C has 2 and 5
I: 3 5
O: A's turn: A has 2 and 1
I: 4 2
O: B's turn: B has 3 and 2
I: 0 0
O: All dices: 2 1 3 2 2 5
Loser is A. (Without optional rules)
Loser is B. (With optional rules)
PART II:
Play this game from the perspective of God, i.e. you can see all of the 6 dice.
Rules of PART II:
Observe all 6 dice and output the optimal combination of a and b, which means it
will certainly
be wrong for any other player to guess again.
For example:
O: All dices: 2 1 3 2 2 5
Best answer: 3 2 (Without optional rules)
Best answer: 4 2 (With optional rules)
注:
O: 用例输出,I: 用例输入,不必写在程序输出里
要求体现代码的良好风格、友好界面、算法和代码的高执行效率等。
其他可选部分:例如,可选择2-5之间的数字作为游戏人数及骰子个数等。
开放时间:
2018年04月02日 星期一 12:00
截止时间:
2018年04月21日 星期六 00:00
上传一个文件
跳过 导航
导航
我的主页