#P13287. [GCJ 2013 #1A] Good Luck

    ID: 15144 远端评测题 6000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2013Special Judge概率论Google Code Jam

[GCJ 2013 #1A] Good Luck

题目描述

Maryam and Peiling have recently been practicing a new number trick, and they need your help to get it right. The trick goes as follows: Maryam starts by picking NN independent random integer numbers, each between 2 and MM, inclusive, appearing with equal probability, and writes them down on NN cards, one number per card. Note that some numbers might be equal. Then, she repeats the following KK times: take a random subset of cards (each card is taken with probability 0.5), and write down the product of the numbers on those cards. Having done all that, she shows all KK products to Peiling, and Peiling's goal is to guess what the original NN numbers were, knowing just NN, MM, and the products.

An example game with N=3N=3, M=4M=4, K=4K=4 might go like this: first, Maryam picks 3 random numbers between 2 and 4, inclusive - let's say she randomly chose A1=3A_1=3, A2=3A_2=3 and A3=4A_3=4. Then, she calculates four products of random subsets of those three numbers. For example, let's say those products are A1A2=9A_1 \cdot A_2=9, A3=4A_3=4, A1A2A3=36A_1 \cdot A_2 \cdot A_3=36, and 1=11=1 (the last product has no numbers in it, so it's equal to 1). Peiling receives numbers 9, 4, 36, 1 from her, and she's also told that N=3N=3 and M=4M=4. In this case, just seeing the number 36 is enough to find what the original numbers were, since the only way to represent that as a product of up to 3 numbers, each up to 4, is 3343 \cdot 3 \cdot 4. So Peiling says that the original numbers were 3, 3 and 4, and the audience is impressed.

In some other cases, guessing the original numbers is not as simple. For example, it might happen that all products are equal to 1. In that case there is no way to know anything about the hidden numbers, so Peiling cannot always be right. However, Peiling knows that Maryam follows the procedure exactly as described above: she selects the first NN numbers as independent uniform integers between 2 and MM, and then selects KK independent random subsets, picking each number into each subset independently with probability 0.5. Help Peiling use that knowledge to make better guesses!

This problem is a bit unusual for Code Jam. You will be given RR independent sets of KK numbers each, and should print an answer for each set — this part is as usual. However, you don't need to get all of your answers right! Your solution will be considered correct if answers for at least XX sets are correct, with the value of XX given in the Limits for the given input, below. However, you must follow the output format, even for sets in which your answer doesn't turn out to be correct. The only thing that can be wrong on any sets, yet still allow you to be judged correct, is the digits you output; but there should still be exactly NN digits printed for each case, and each digit must be between 2 and MM.

This problem involves randomness, and thus it might happen that even the best possible solution doesn't make XX correct guesses (remember the situation when all products are equal to 1?) for a certain input. Because of that, this problem doesn't have a Large input, but instead has two Small inputs. That means you can try again if you think you got unlucky. You may only attempt to solve the second Small input once you have solved the first one. Otherwise, both Small inputs work in the same way as Small inputs for any other problem: you may try multiple times, and there is a 4-minute penalty for incorrect submissions if you later solve that input, even if the only reason you got it wrong was chance.

Good luck!

输入格式

The first line of the input gives the number of test cases, TT, which is always equal to 1. The second line of the input file contains four space-separated integers RR, NN, MM and KK, in that order. The next RR lines describe one set of KK products each. Each of those lines contains KK space-separated integers — the products that Maryam passes to Peiling. It is guaranteed that all sets in the input are generated independently randomly according to the procedure from the problem statement.

输出格式

On the first line, output "Case #1:". On each of the next RR lines output NN digits — your guess for Maryam's hidden numbers for the corresponding set of products. You can print the numbers for each set in any order, but there must be exactly NN digits, each between 2 and MM, inclusive (note that M<10M<10, so none of the numbers will be more than one digit). Do not put spaces between the digits.

1
2 3 4 4
9 4 36 1
1 1 1 1
Case #1:
343
222

提示

Sample Explanation

The sample input doesn't follow the limitations for either input. In the sample input, you need to get at least X=1X=1 sets right.

In the sample input, Maryam picked the numbers 3,3,43, 3, 4 the first time, and the numbers 2,4,42, 4, 4 the second time. In the sample output, Peiling guessed correctly the first time, but not the second time.

First Small dataset (10 Pts, Test set 1 - Visible)

  • T=1T = 1.
  • R=100R = 100.
  • N=3N = 3.
  • M=5M = 5.
  • K=7K = 7.
  • You need to get at least X=50X=50 sets right.

Second Small dataset (31 Pts, Test set 2 - Visible)

  • T=1T = 1.
  • R=8000R = 8000.
  • N=12N = 12.
  • M=8M = 8.
  • K=12K = 12.
  • You need to get at least X=1120X=1120 sets right.