CRYPT1 Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
With the given n numbers, replace the following vertical, how many correct vertical type can be generated?
* * *
X * *
-------
* * *
* * *
-------
* * * *
Input file, the first row n means there are n digits, the second line gives all the numbers (space split. )
"Data Range"
All numbers ∈{1,2,3,4,5,6,7,8,9}
"Input Sample"
5
2 3 4) 6 8
"Output Example"
1
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
In vertical, the following three results can be calculated as long as the multiplier and the multiplier are known.
Therefore, as long as the enumeration of the two number is good, altogether 5, 9^5<100000, must be no problem.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
Once again AC.
At the beginning of the sample test, the reason is that the number of three results did not determine whether the digits are correct. Can say, or read the question is not rigorous careful.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Code
1 /*2 id:icedrea13 prob:crypt14 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten One intn,d[Ten]; A BOOLhave[Ten]; - - BOOLOkintnum) the { - while(num) - { - if(!have[num%Ten])return false; +Num/=Ten; - } + return true; A } at BOOLOkintAintBintCintDintE) - { - inti = A * -+b*Ten+C; - intj = d*Ten+E; - intx = i*e;if(x< -|| X>999)return false; - inty = i*d;if(y< -|| Y>999)return false; in intz = x+y*Ten;if(z< +|| Z>9999)return false; - returnOK (x) && ok (y) &&ok (z); to } + - intMain () the { *Ifstreaminch("crypt1.in"); $Ofstream out("Crypt1.out");Panax Notoginseng - inch>>N; the for(intI=1; i<=n;++i) {inch>>D[i]; have[d[i]]=true; } + A ints=0; the for(intA=1; a<=n;++a) + for(intb=1; b<=n;++b) - for(intC=1; c<=n;++c) $ for(intD=1;d <=n;++d) $ for(intE=1; e<=n;++e) - if(OK (d[a],d[b],d[c],d[d],d[e])) + +s; - out<<s<<Endl; the - inch. Close ();Wuyi out. Close (); the return 0; -}
Usaco Section1.3 Prime cryptarithm Problem Solving report