Problem : [Noip2008]火柴棒等式

Problem : [Noip2008]火柴棒等式

Time Limit: 1 Sec Memory Limit: 128 MB

Description

给你 n 根火柴棒,你可以拼出多少形如“A+B=C”的等式?等式中的A、B、C是用火柴棒拼出的整数(若该整数非零,则最高位不能为零)。用火柴棒拼数字 0~9 的拼法如图所示:
在这里插入图片描述
注意
1.加号和等号各自需要 2 根火柴棒
2.如果 A≠B ,则 A+B=C 或 B+A=C 视为不同的等式(A、B、C>=0)
3.n 根火柴棒必须全部用上??
Input
输入一行,有一个整数 n (n<=24)。
Output
输出一行,有一个整数,表示能拼成的不同等式的数目。
Sample Input
14
Sample Output
2
2个等式为:
0+1=1
1+0=1

code:

#include<stdio.h>
#define maxn 1000
int a[10]= {6,2,5,5,4,5,6,3,7,6};
int get(int x) {
	int sum=0;
	if(x==0)return a[0];
	while(x>0)sum+=a[x%10],x/=10;
	return sum;
}
int main() {
	int i,j,k,n,ans=0;
	scanf("%d",&n);
	n-=4;
	for(i=0; i<=maxn; i++)
		if(get(i)+get(i)+get(i+i)==n)ans++;
	for(i=0; i<=maxn; i++)
		for(j=0; j<=maxn; j++)
			if(i!=j)
				if(get(i)+get(j)+get(i+j)==n)ans++;
	printf("%d\n",ans);
	return 0;
}
posted @ 2019-02-01 18:37  ZhaoChongyan  阅读(122)  评论(0编辑  收藏  举报