输入输出格式 Input/output
输入格式:
输入文件matches.in共一行,又一个整数n(n<=24)。
输出格式:
输出文件matches.out共一行,表示能拼成的不同等式的数目。
输入文件matches.in共一行,又一个整数n(n<=24)。
输出格式:
输出文件matches.out共一行,表示能拼成的不同等式的数目。
题目描述 Description
输入样例:
样例输入1:
14
样例输入2:
18
输出样例:
样例输出1:
2
样例输出2:
9
说明 description
1 #include<stdio.h> 2 int main() 3 { 4 int i,j,k,n,x,ans=0; 5 int a[2001]={0};//对于数组a清零 6 /*=========================================*///打表,记录每个数字要用的火柴棒 7 a[0]=6;a[1]=2;a[2]=5;a[3]=5;a[4]=4; 8 a[5]=5;a[6]=6;a[7]=3;a[8]=7;a[9]=6; 9 /*=========================================*/ 10 //freopen("matches.in","r",stdin); 11 //freopen("matches.out","w",stdout); 12 scanf("%d",&n); 13 for(i=10;i<1000;i++)//从10开始找,10以下都是没有答案的 14 { 15 x=i; 16 while(x>0) 17 { 18 a[i]+=a[x%10]; 19 x/=10; 20 } 21 } 22 n-=4;//加法和等号要用去4根火柴棒 23 /*--------------------------------------------------------------*///两重for循环开始找起! 24 for(i=0;i<=1000;i++)//循环到爆 25 { 26 if(a[i]<n)//只有当加数小于和时,才有可能加上去 27 { 28 for(j=0;j<=1000;j++)//循环到爆 29 if(a[i]+a[j]<n)//两个加数比和要小,执行 30 { 31 k=i+j;//加上和 32 /*========================*///模拟加法过程 33 if(a[i]+a[j]+a[k]==n) 34 { 35 ans++;//找到一种方案,ans++ 36 } 37 /*========================*/ 38 } 39 } 40 } 41 /*--------------------------------------------------------------*/ 42 printf("%d\n",ans); 43 return 0; 44 }
原文:http://www.cnblogs.com/geek-007/p/4666556.html