计蒜客 难题题库 211 火柴棍游戏
2015-08-10 10:12
253 查看
32次
9.37%
1000ms
65536K
给你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根火柴棍必须全部用上
输入文件matches.in共一行,又一个整数n(n< =24)。
输出文件matches.out共一行,表示能拼成的不同等式的数目。
【输入输出样例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
输出:
9.37%
1000ms
65536K
给你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根火柴棍必须全部用上
输入文件matches.in共一行,又一个整数n(n< =24)。
输出文件matches.out共一行,表示能拼成的不同等式的数目。
【输入输出样例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
样例1
输入:【输入样例1】 14 【输入样例2】 18
输出:
【输出样例1】 2 【输出样例2】 9
#include<iostream> using namespace std; const int a[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int count(int n){ int weight = 10; while(weight <= n){ weight *= 10; } weight /= 10; int res = 0; while(weight){ res += a[n / weight]; n %= weight; weight /= 10; } return res; } int main(){ int n, res = 0; cin >> n; n -= 4; for(int i = 0; i < 1000; ++i){ for(int j = 0; j < 1000; ++j){ if(count(i) + count(j) + count(i + j) == n){ ++res; } } } cout << res << endl; }
相关文章推荐
- 二分图最大匹配总结
- 在 ServiceModel 客户端配置部分中,找不到引用协定“PmWs.PmWebServiceSoap”的默认终结点元素
- 面试题3
- APP夜间模式的两种实现方式
- Android Data Binding简单介绍
- SQL语句select from where group by having order by 顺序
- 写出阿波罗登月代码的女人
- 生成中奖文字图片
- 使用JDeveloper 11g 检查程序性能
- 计蒜客 难题题库 210 矩阵游戏
- 解决Server2008下远程桌面连接“由于没有终端服务器许可证服务器可以提供许可证”
- PMP杂谈--项目管理计划
- Ubuntu 14.10 下NodeJS Cannot find module 'npmlog'
- iOS多线程编程之NSThread的使用
- UIScrollView
- 快速上手之 C#操作WORD对象模型
- 第二章 cpp-empty-test:还是那个HelloWorld!
- poj 1458 Common Subsequence【LCS】
- 友元函数、友元类、访问私有数据成员、友元关系
- 使用JDeveloper 11g 检查内存泄漏