P1149 Match Stick equation
-
- Topic provider The user does not exist
- Tag Search/Enumeration simulation Noip raise group
- Difficulty Popularization-
Submit a discussion of the problem record
Title Description
Give you n a match stick, you can spell how many shape like "a+b=c" equation? A, B, and C in the equation are integers that are spelled with a match stick (if the number is nonzero, the highest bit cannot be 0). Spell the number 0-9 with a match stick:
Attention:
The plus sign and the equals sign each need two sticks
If A≠b, A+b=c and b+a=c are considered different equations (A, B, c>=0)
- N sticks must all be used.
Input output Format input format:
The input file matches.in a total of one line, and another integer n (n<=24).
Output format:
The output file matches.out a common line that represents the number of different equations that can be spelled.
Input and Output Sample input example # #:
Sample input 1:14 Example input 2:18
Sample # # of output:
Sample output 1:2 Sample output 2:9
Description
"Input and output Example 1 explanation"
2 equations for 0+1=1 and 1+0=1.
"Input and output Example 2 explanation"
The 9 equations are:
0+4=40+11=111+10=112+2=42+7=94+0=47+2=910+1=1111+0=11
Analysis: This problem is not very difficult, the first to use an array to 0~9 number of matches needed to show the number of match sticks, but more than 9 how to express it? A 10 binary natural number is made up of 0~9, then we can get the number of each position in the MOD10, and then calculate it according to the data in the array. However, it is important to note that the operation symbol also counts the number of matches.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intN,ans =0;ints[Ten] = {6,2,5,5,4,5,6,3,7,6};intShuliang (intx) { if(x = =0) return 6; intsum =0; while(X >0) {sum+ = s[x%Ten]; X/=Ten; } returnsum;}intMain () {scanf ("%d",&N); for(inti =0; I < +; i++) for(intj =0; J < +; J + +) { intA = Shuliang (i) +Shuliang (j); intb = Shuliang (i +j); if(A + B +4==N) Ans++; } printf ("%d", ans); return 0;}
noip2008 Match Stick equation