[NOIP2008] 火柴棒等式

220. [NOIP2008] 火柴棒等式

★   输入文件: matches.in   输出文件: matches.out    简单对比
时间限制:1 s   内存限制:128 MB

【问题描述】

给你n根火柴棒,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棒拼出的整数(若该数非零,则最高位不能是0)。用火柴棒拼数字0--9的拼法如图所示:

Image:Noip08match.jpg

注意

  1. 加号与等号各自需要2根火柴棒
  2. 如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)
  3. n根火柴棒必须全部用上

【输入】

输入文件matches.in共一行,有一个整数n(n<=24)。

【输出】

输出文件matches.out共一行,有一个整数,表示能拼成的不同等式的数目。

【输入输出样例1】

matches.in

14

matches.out

2

【输入输出样例1解释】

2个等式为0+1=1和l+0=1

【输入输出样例2】

matches.in

18

matches.out

9

【输入输出样例2解释】

9个等式为:

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
 
 
直接模拟。。枚举A,B。
#include<cstdio>
using namespace std;
int need[]={6,2,5,5,4,5,6,3,7,6};
int ans;

int cnt(int cur){
    int ans=0,ret;
    if(cur==0) return 6;
    while(cur>0){
        ret=cur%10;
        ans+= need[ret];
        cur/=10;
    }
    return ans;
}
int main(){
    freopen("matches.in","r",stdin);
    freopen("matches.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=0;i<=1000;i++){
       for(int j=0;j<=1000;j++){
           int a=cnt(i);  int b=cnt(j);
           int d=cnt(i+j);
           int c=n-4-a-b;
           if(d==c){
                ans++;
           }
       }
    }
    printf("%d\n",ans);
    return 0;
}


 
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值