Title Description 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:
1. The plus sign and the equals sign each need two sticks
2. If a≠b, A+b=c and b+a=c are considered different equations (A, B, c>=0)
3. N sticks must all be used
input/output format input/output
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 sample Input/output
sample Test point # #
Input Sample:
Sample Input 1:
14
Sample Input 2:
18
Sample output:
Sample Output 1:
2
Sample Output 2:
9
Description 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=4
0+11=11
1+10=11
2+2=4
2+7=9
4+0=4
7+2=9
10+1=11
11+0=11 idea: You can first put the number of matches required for each number table (in the array), and then from 10 onwards to find the first Addend (101 under the direct output 0, no answer), and then two for the loop, looking for the first second addend (set two criteria to determine whether the first Addend, Two addend and less than and), the establishment of the ans++, the body is purely analog ... The code is as follows:
1#include <stdio.h>2 intMain ()3 {4 inti,j,k,n,x,ans=0;5 inta[2001]={0};//for array a clear 06 /*=========================================*///make a watch, record the match stick for each number7a[0]=6; a[1]=2; a[2]=5; a[3]=5; a[4]=4;8a[5]=5; a[6]=6; a[7]=3; a[8]=7; a[9]=6; 9 /*=========================================*/Ten //freopen ("matches.in", "R", stdin); One //freopen ("Matches.out", "w", stdout); Ascanf"%d",&N); - for(i=Ten;i< +; i++)//starting from 10, 10 below are no answers. - { thex=i; - while(x>0) - { -a[i]+=a[x%Ten]; +X/=Ten; - } + } An-=4; //Add and equals sign to use 4 sticks. at /*--------------------------------------------------------------*///dual for loop starts to look up! - for(i=0; i<= +; i++)//Loop to Burst - { - if(a[i]<n)//only when the addend is less than and when it is possible to add - { - for(j=0; j<= +; j + +)//Loop to Burst in if(a[i]+a[j]<n)//two addend and to be small, perform - { toK=i+j;//Plus and + /*========================*///simulating the addition process - if(a[i]+a[j]+a[k]==N) the { *ans++;//Find a solution, ans++ $ }Panax Notoginseng /*========================*/ - } the } + } A /*--------------------------------------------------------------*/ theprintf"%d\n", ans); + return 0; -}
Rokua-Match stick Equation-noip2008 improve group rematch