|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||1536 MB||14||7||7||63.636%|
Amina has six coins, numbered from 1 to 6. She knows that the coins all have different weights. She would like to order them according to their weight. For this purpose she has developed a new kind of balance scale.
A traditional balance scale has two pans. To use such a scale, you place a coin into each pan and the scale will determine which coin is heavier.
Amina’s new scale is more complex. It has four pans, labeled A, B, C, and D. The scale has four different settings, each of which answers a different question regarding the coins. To use the scale, Amina must place exactly one coin into each of the pans A, B, and C. Additionally, in the fourth setting she must also place exactly one coin into pan D.
The four settings will instruct the scale to answer the following four questions:
Write a program that will order Amina’s six coins according to their weight. The program can query Amina’s scale to compare weights of coins. Your program will be given several test cases to solve, each corresponding to a new set of six coins.
Your program should implement the functions
orderCoins. During each run of your program, the grader will first call
init exactly once. This gives you the number of test cases and allows you to initialize any variables. The grader will then call
orderCoins() once per test case.
T: The number of test cases your program will have to solve during this run.
Tis an integer from the range 1, ..., 18.
answer(), the function
orderCoins()should return. It has no return value.
You may use the following grader functions in your program:
answer(W)— your program should use this function to report the answer that it has found.
W: An array of length 6 containing the correct order of coins.
Wshould be the coin numbers (i.e., numbers from 1 to 6) in order from the lightest to the heaviest coin.
orderCoins(), once per test case.
getHeaviest(A, B, C),
getLightest(A, B, C),
getMedian(A, B, C)— these correspond to settings 1, 2 and 3 respectively for Amina’s scale.
C: The coins that are put in pans A, B, and C, respectively.
Cshould be three distinct integers, each between 1 and 6 inclusive.
C: the number of the appropriate coin. For example,
getHeaviest(A, B, C)returns the number of the heaviest of the three given coins.
getNextLightest(A, B, C, D)— this corresponds to setting 4 for Amina’s scale
D: The coins that are put in pans A, B, C, and D, respectively.
Dshould be four distinct integers, each between and inclusive. The function returns one of the numbers A, B, and C: the number of the coin selected by the scale as described above for setting 4. That is, the returned coin is the lightest amongst those coins on pans A, B, and C that are heavier than the coin in pan D; or, if none of them is heavier than the coin on pan D, the returned coin is simply the lightest of all three coins on pans A, B, and C.
There are no subtasks in this problem. Instead, your score will be based on how many weighings (total number of calls to grader functions
getNextLightest()) your program makes.
Your program will be run multiple times with multiple test cases in each run. Let r be the number of runs of your program. This number is fixed by the test data. If your program does not order the coins correctly in any test case of any run, it will get 0 points. Otherwise, the runs are scored individually as follows.
Let Q be the smallest number such that it is possible to sort any sequence of six coins using Q weighings on Amina’s scale. To make the task more challenging, we do not reveal the value of Q here.
Suppose the largest number of weighings amongst all test cases of all runs is Q + y for some integer y. Then, consider a single run of your program. Let the largest number of weighings amongst all T test cases in this run be Q + x for some non-negative integer x. (If you use fewer than Q weighings for every test case, then x = 0.) Then, the score for this run will be 100/(r((x+y)/5+1)).
In particular, if your program makes at most weighings in each test case of every run, you will get 100 points.
Suppose the coins are ordered 3 4 6 2 1 5 from the lightest to the heaviest.
||6||Coin 6 is the median among coins 4, 5, and 6.|
||1||Coin 1 is the heaviest among coins 1, 2, and 3.|
||3||Coins 2, 3, and 4 are all lighter than coin 5, so the lightest among them (3) is returned.|
||6||Coins 1 and 6 are both heavier than coin 4. Among coins 1 and 6, coin 6 is the lightest one.|
||5||Coin 5 is the heaviest among coins 3, 5, and 6.|
||1||Coin 1 is the median among coins 1, 5, and 6.|
||6||Coin 6 is the median among coins 2, 4, and 6.|
||The program found the right answer for this test case.|
The sample grader reads input in the following format:
For instance, an input that consists of two test cases where the coins are ordered 1 2 3 4 5 6 and 3 4 6 2 1 5 looks as follows:
2 1 2 3 4 5 6 3 4 6 2 1 5
The sample grader prints the array that was passed as a parameter to the
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)