火柴棒等式
来源:互联网 发布:免费移动app直播源码 编辑:程序博客网 时间:2024/06/11 01:24
【问题描述】
给你n根火柴棒,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棒拼出的整数(若该数非零,则最高位不能是0)。用火柴棒拼数字0--9的拼法如图所示:
注意
- 加号与等号各自需要2根火柴棒
- 如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)
- 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=40+11=111+10=112+2=42+7=94+0=47+2=910+1=1111+0=11#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(){ 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;}
0 0
- [NOIP2008]火柴棒等式
- 1766. 火柴棒等式
- [NOIP2008] 火柴棒等式
- 火柴棒等式
- 1106: 火柴棒等式
- noip 火柴棒等式
- P1012火柴棒等式
- NOIP2008 火柴棒等式
- noip2008火柴棒等式
- 火柴棒等式
- NOIP2008 火柴棒等式
- openjudge 火柴棒等式
- 火柴棒等式
- [NOIP2008] 火柴棒等式
- NOIP2008 火柴棒等式
- POJ8466火柴棒等式
- 火柴棒等式
- NOIp2008 火柴棒等式
- web.config中配置数据库连接字符串
- mybaties 多个参数传参的三种解决方案
- 系统启动过程中出现:error: no such partition grub rescue
- 一次项目杂记
- 判断空值的全局方法
- 火柴棒等式
- Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04
- WEB前端开发成长指南
- Warning: Using a password on the command line interface can be insecure.
- ie条件注释
- selenium +python 判断当前页面某一元素的状态
- Rabbit MQ学习笔记
- C#识别图像中线的条数
- Android 开发系列(5) - 代码混淆