zcmu-1967
2017-08-24 15:13
99 查看
1967: 火柴棒等式
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 15 Solved: 11
[Submit][Status][Web
Board]
Description
给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棍拼出的整数(若该数非零,则最高位不能是0)。用火柴棍拼数字0-9的拼法如图所示:注意:
1. 加号与等号各自需要两根火柴棍
2. 如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)
3. n根火柴棍必须全部用上
Input
输入文件matches.in共一行,又一个整数n(n<=24)。Output
输出文件matches.out共一行,表示能拼成的不同等式的数目。Sample Input
1418Sample Output
29HINT
【输入输出样例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
Source
NOIP2008提高组思路:预处理+枚举,心痛的一题,哎。可以算得24根火柴可以最大的组成1110+1=1111,所以可以假设最大的数为1111
代码:
#include<cstdio> #include<cstring> using namespace std; int main() { int m[2010]; int a[10]={6,2,5,5,4,5,6,3,7,6}; memset(m,0,sizeof(m)); for(int i=0; i<=1999; i++) { if(i==0)m[i]=a[i]; else { int x=i; while(x) { int xx=x%10; m[i]+=a[xx]; x/=10; } } } int n; while(~scanf("%d",&n)) { int ans=0; for(int i=0; i<=1111; i++) for(int j=0; j<=1111; j++) { if(m[i]+m[j]+m[i+j]+4==n)ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- zoj 1967 Fiber Network
- zcmu1672
- ACM-补提交 (ZCMU-1617)
- 洛谷1967 火车运输 kruskal求最大生成树 倍增LCA维护最小值
- ZCMU—1687
- ZCMU—1487
- ZCMU—1053
- ZCMU—1595
- ZCMU-1131-致青春
- ZCMU—1457
- ZCMU-1417-快速幂
- ZCMU—1551
- ZCMU-1343-素数对
- ZCMU-1180(大数相乘)
- ZCMU-1720-死亡如风,我要装逼
- ZCMU-1607-大二下之悬梁刺股
- ZCMU-1841-完美的代价
- ZCMU-1863-zbj的长跑
- poj2550&&zcmu1867——Zipf's Law
- ZCMU—H