2 人解决,5 人已尝试。
2 份提交通过,共有 12 份提交。
9.3 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
Mr.A is a smart shopkeeper who uses an ordinary beam balance for measurements. He owns a set of cubes weighing 1g, 3g, 9g, 27g, 81g, 243g, . . ., respectively. Mr.A owns exactly one cube of a given weight, and he is allowed to place cubes in either pan. A sack of unknown weight has been placed in the Left pan of the beam balance.
Use your programming skills to help the shopkeeper to figure out which cubes to place in which pan so that the two pans are balanced. This will help her figure out the weight of the sack.
Input will consist of a series of positive integers, one integer per line. Integers lie between 1 and 2^31 - 1, both inclusive. Each integer represents the weight of the sack placed in the Left pan.
Output should be in the format shown below. The string after the = symbol consists of L, R or N, depending on whether the corresponding cube was placed on the Left pan, the Right pan or not used at all.
Sequences of trailing N symbols must be trimmed. This means that the last symbol is necessarily R.
For example, output 499 = RRRNNLR means that to measure 499g, cubes weighing 1g, 3g , 9g and 729g have to be placed in the Right pan, and the cube weighing 243g has to be placed in the Left pan. Other cubes are not used at all.
UPDATE: The input is terminated by end-of-file
1 2 30 4 499 368
1 = R 2 = LR 30 = NRNR 4 = RR 499 = RRRNNLR 368 = LNLLLLR
2 人解决,5 人已尝试。
2 份提交通过,共有 12 份提交。
9.3 EMB 奖励。
创建: 16 年,2 月前.
修改: 6 年,11 月前.
最后提交: 1 年,1 月前.
来源: N/A