Usaco Section1.3 Prime cryptarithm Problem Solving report

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.