USACO Section 1.3.6 Prime Cryptarithm
来源:互联网 发布:2017mac最新系统是什么 编辑:程序博客网 时间:2024/06/04 18:21
题目
The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits {2,3,5,7} is selected, the cryptarithm is called a PRIME CRYPTARITHM.
* * * x * * ------- * * * <-- partial product 1 * * * <-- partial product 2 ------- * * * *Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed.
Note that the 'partial products' are as taught in USA schools. The first partial product is the product of the final digit of the second number and the top number. The second partial product is the product of the first digit of the second number and the top number.
Write a program that will find all solutions to the cryptarithm above for any subset of digits from the set {1,2,3,4,5,6,7,8,9}.
PROGRAM NAME: crypt1
INPUT FORMAT
Line 1:N, the number of digits that will be usedLine 2:N space separated digits with which to solve the cryptarithmSAMPLE INPUT (file crypt1.in)
52 3 4 6 8
OUTPUT FORMAT
A single line with the total number of unique solutions. Here is the single solution for the sample input:
2 2 2 x 2 2 ------ 4 4 4 4 4 4 --------- 4 8 8 4
SAMPLE OUTPUT (file crypt1.out)
1
思路
代码
/*ID:zhrln1PROG:crypt1LANG:C++*/#include <cstdio>int n,b[11],k,ans;int hash(int v){ while (v){ if (!b[v%10]) return 0; v/=10; } return 1;}int main(){freopen("crypt1.in","r",stdin);freopen("crypt1.out","w",stdout);scanf("%d",&n);for (int i(1);i<=n;i++){scanf("%d",&k);b[k]=1;}for (int i(111);i<1000;i++){if (hash(i)){for (int j(11);j<100;j++){if (i*j<10000 && i*(j/10)<1000 && i*(j%10)<1000 && hash(j) && hash(i*(j%10)) && hash(i*(j/10)) && hash(i*j)) { ans++; // printf("%d * %d = %d0 + %d = %d \n",i,j,i*(j/10),i*(j%10),i*j);}}}}printf("%d\n",ans);return 0;}
- USACO Section 1.3.6 Prime Cryptarithm
- [USACO]Section 1.3 Prime Cryptarithm
- USACO Section 1.3 Prime Cryptarithm
- USACO Section 1.3 Prime Cryptarithm
- USACO-Section 1.3 Prime Cryptarithm[...]
- USACO section 1.3 Prime Cryptarithm
- USACO Section 1.3 Prime Cryptarithm
- USACO section 1.3.4 Prime Cryptarithm
- USACO Section 1.3.4 Prime Cryptarithm
- USACO-Section 1.3 Prime Cryptarithm(枚举)
- USACO-section 1.3 Prime Cryptarithm[hash]
- USACO Training Section 1.3 Prime Cryptarithm 解题报告&AC代码
- USACO 1.3-Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- usaco 1.3 Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO 1.3-Prime Cryptarithm
- JS 汉字解码
- 关于UtilTimerStack类的使用--XWork2、Struts2内置性能诊断类 --只为学习
- 设置眼睛保护色
- My97DatePicker IE chrome失效,路径问题
- J2EE十三种技术规范介绍
- USACO Section 1.3.6 Prime Cryptarithm
- linux命令--vmstat
- Php魔术方法学习实例
- win7 64位 MySQLdb: python_mod,mysql安装
- Http教程
- 直接拿来用!最火的Android开源项目
- CSDN博客
- win7下安装配置tomcat,java运行环境
- 锁定页面滚动条以及iframe拿到父页面的节点值