【模拟】洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm
来源:互联网 发布:网络90后帅奶爸 编辑:程序博客网 时间:2024/05/02 17:24
题目描述
下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式。
数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0。
注意一下在美国的学校中教的“部分乘积”,第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积.
写一个程序找出所有的牛式。
输入输出格式
输入格式:
Line 1:数字的个数n。
Line 2:N个用空格分开的数字(每个数字都属于{1,2,3,4,5,6,7,8,9})。
输出格式:
共一行,一个数字。表示牛式的总数。
输入输出样例
输入样例#1:
5
2 3 4 6 8
输出样例#1:
1
说明
题目翻译来自NOCOW。
USACO Training Section 1.3
代码
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;bool flag[10];int sum;void read(int &x){ x=0; char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); }}int main(){ int n; read(n); for(int i=1;i<=n;++i) { int x; read(x); flag[x]=true; } for(register int i=1;i<=9;++i) { if(flag[i]) { for(register int j=1;j<=9;++j) { if(flag[j]) { for(register int k=1;k<=9;k++) { if(flag[k]) { for(register int m=1;m<=9;m++) { if(flag[m]) { for(register int n=1;n<=9;n++) { if(flag[n]) { bool p=true; int s1=i*100+j*10+k,s2=m*10+n; int temp=s1*m; while(temp>0) { if(temp>999) { p=false; break; } int x=temp%10; if(!flag[x]) { p=false; break; } temp/=10; } if(!p)continue; temp=s1*n; while(temp>0) { if(temp>999) { p=false; break; } int x=temp%10; if(!flag[x]) { p=false; break; } temp/=10; } if(!p)continue; temp=s1*s2; while(temp>0) { if(temp>9999) { p=false; break; } int x=temp%10; if(!flag[x]) { p=false; break; } temp/=10; } if(!p)continue; sum++; } } } } } } } } } } printf("%d",sum); return 0;}
0 0
- 【模拟】洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm
- P1211 [USACO1.3]牛式 Prime Cryptarithm
- [USACO1.3]牛式 Prime Cryptarithm
- 【USACO1.3】牛式 Prime Cryptarithm
- USACO1.3 牛式 Prime Cryptarithm
- USACO1.3牛式 Prime Cryptarithm
- 【洛谷1211 [USACO1.3]牛式 Prime Cryptarithm】【枚举】
- USACO1.3.4 Prime Cryptarithm(牛式)
- 这压缩,太强了![USACO1.3]牛式 Prime Cryptarithm
- USACO1.3.3 Prime Cryptarithm (crypt1)
- USACO1.3.3 Prime Cryptarithm (crypt1)
- Prime Cryptarithm牛式
- 【USACO-Chapter1-1.3】【模拟】Prime Cryptarithm
- USACO 1.3. Prime Cryptarithm 牛式
- USACO 1.3.3 Prime Cryptarithm
- USACO Section1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- Undraw the Trees UVA
- FL Studio钢琴卷轴之居中与分离命令
- H5移动端常见问题及注意事项
- echarts图表学习之调整条形图的位置
- Hive 数据类型和存储格式、建表操作
- 【模拟】洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm
- 详讲FL Studio钢琴卷轴之助手命令
- AndroidManifest.xml中四大组件的permission、 android:exported 属性详解和UID机制
- There are no resources that can be added or removed from the server. .
- 基于ARP的网络扫描工具netdiscover
- Solr学习总结(八)IK 中文分词的配置和使用
- java实现闰年
- C# 学习笔记 2
- curl模拟post进行表单提交