[NOIP2008] 提高组 洛谷P1149 火柴棒等式
2016-11-03 13:11
357 查看
题目描述
给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棍拼出的整数(若该数非零,则最高位不能是0)。用火柴棍拼数字0-9的拼法如图所示:
注意:
-
加号与等号各自需要两根火柴棍
-
如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)
- n根火柴棍必须全部用上
输入输出格式
输入格式:
输入文件matches.in共一行,又一个整数n(n<=24)。
输出格式:
输出文件matches.out共一行,表示能拼成的不同等式的数目。
输入输出样例
输入样例#1:样例输入1: 14 样例输入2: 18输出样例#1:
样例输出1: 2 样例输出2: 9
说明
【输入输出样例1解释】
2个等式为0+1=1和1+0=1。
【输入输出样例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
打表列出每个数字需要的火柴棒数量。枚举两个加数看能否满足式子即可。
加数要循环枚举到1100左右。
/*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> using namespace std; const int mxn=100010; const int a[10]={6,2,5,5,4,5,6,3,7,6}; // 0 1 2 3 4 5 6 7 8 9 int n; int gt(int x){ if(!x)return a[0]; int res=0; while(x){ res+=a[x%10]; x/=10; } return res; } int main(){ cin>>n; int i,j; int cnt=0; for(i=0;i<=1100;i++) for(j=0;j<=1100;j++){ int r=i+j; int bas=4;//+ = if(gt(i)+gt(j)+bas+gt(r)==n)cnt++; } cout<<cnt<<endl; return 0; }
相关文章推荐
- 洛谷 P1149 火柴棒等式2008 NOIp提高组
- 洛谷-火柴棒等式-NOIP2008提高组复赛
- 火柴棒等式(洛谷 1149 && NOIp2008 提高组 T2 )
- NOIP2008提高组火柴棒等式(模拟)——yhx
- |洛谷|搜索|NOIP2008|P1149 火柴棒等式
- 【枚举】Vijos P1496 火柴棒等式 【NOIP2008提高组第二题】
- noip2008提高组——火柴棒等式
- 2008NOIp提高组 火柴棒等式
- NOIP 2008 提高组 复赛 matches 火柴棒等式
- 【提高组NOIP2008】火柴棒等式
- [NOIP2008] 提高组 洛谷P1155 双栈排序
- <NOIP> 24 . P1149 火柴棒等式
- NOIP2008 火柴棒等式
- noip2008 火柴棒等式
- NOIP 2008 火柴棒等式 解题报告
- 【枚举】[NOIP2008]火柴棒等式
- NOIP 2008 解题报告(笨小猴,火柴棒等式,传纸条,双栈排序)
- NOIP2008 火柴棒等式
- noip2008 火柴棒等式 (暴力枚举)
- [NOIP2013提高&洛谷P1966]火柴排队 题解(树状数组求逆序对)