#P1236. 算24点
算24点
Description
Decades ago, a number game became popular worldwide and is still enjoyed today. In China, we call this game "24 Game". As a player, you are given 4 natural numbers between and as operands. Your task is to perform arithmetic operations on these 4 operands so that the result equals .
You may use only the operations and . You may also use to change the order of operations. Note: all intermediate results must be integers, so some divisions are not allowed (for example, is valid, while is invalid). Here is a concrete example of the game:
If the 4 operands are , , , and , then one possible answer is .
Input Format
A single line containing four natural numbers between and (inclusive).
Output Format
If a solution exists, output any one solution. The output consists of three lines, each describing one computation step.
- The first line is two input numbers, an operator, and the result after the operation.
- The second line is the result from the first line combined with one remaining input number, an operator, and the new result, or the result of applying an operator to the other two input numbers.
- The third line combines the previous result, the second line’s result or the remaining number, an operator, and . If two operands are different, output the larger one first.
If there is no solution, output No answer!.
If multiple valid solutions exist, output any one of them.
Note: all operation results must be positive integers.
1 2 3 7
2+1=3
7*3=21
21+3=24
Hint
Thanks to chenyy for the special judge.
: Added a new set of hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号