USACO Prime Cryptarithm Accepted

来源:互联网 发布:送女朋友什么口红知乎 编辑:程序博客网 时间:2024/06/05 23:50
传说这道题容易超时,结果一遍就过了,意外^_^。

USACO Training Grader Results for DaN marner [danmarn1]

TASK: crypt1LANG: CCompiling...Compile: OKExecuting...      Test 1: TEST OK [0.004 secs]      Test 2: TEST OK [0.004 secs]      Test 3: TEST OK [0 secs]      Test 4: TEST OK [0.004 secs]      Test 5: TEST OK [0.004 secs]      Test 6: TEST OK [0.004 secs]      Test 7: TEST OK [0.004 secs]All tests OK.

YOUR PROGRAM ('crypt1') WORKED FIRST TIME! That's fantastic-- and a rare thing. Please accept these special automatedcongratulations.

Here are the test data inputs:

------- test 1 -------52 3 4 6 8------- test 2 -------42 3 5 7------- test 3 -------11------- test 4 -------74 1 2 5 6 7 3------- test 5 -------89 1 7 3 5 4 6 8------- test 6 -------61 2 3 5 7 9------- test 7 -------91 2 3 4 5 6 7 8 9----------------------
Keep up the good work!
 

Thanks for your submission!
 


枚举100-999乘10-99,这个过程中分别判断产生的竖式中每一项是否符合要求即可。

附题如下:


Prime Cryptarithm

The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits {2,3,5,7} is selected, the cryptarithm is called a PRIME CRYPTARITHM.

      * * *   x    * *    -------      * * *    * * *    -------    * * * *
Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed.

Write a program that will find all solutions to the cryptarithm above for any subset of digits from the set {1,2,3,4,5,6,7,8,9}.

PROGRAM NAME: crypt1

INPUT FORMAT

Line 1: N, the number of digits that will be used Line 2: N space separated digits with which to solve the cryptarithm

SAMPLE INPUT (file crypt1.in)

52 3 4 6 8

OUTPUT FORMAT

A single line with the total number of unique solutions. Here is the solution for the sample input:

      2 2 2    x   2 2     ------      4 4 4    4 4 4  ---------    4 8 8 4

SAMPLE OUTPUT (file crypt1.out)

1