UASCO Prime Cryptarithm
来源:互联网 发布:淘宝申请开店流程 编辑:程序博客网 时间:2024/06/05 18:56
题目点这里
题解:
简单深搜,很暴力。
代码实现:
/*ID: eashionLANG: C++TASK: crypt1*/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>#define MAX 12using namespace std;int N;int res;int Lis[MAX];int num[MAX];map<int,int> mm;//void print();void dfs(int len);bool test(int x,int len);int main(){ freopen("crypt1.in","r",stdin); freopen("crypt1.out","w",stdout); while( scanf("%d",&N) != EOF ){ res = 0; memset(Lis,0,sizeof(Lis)); memset(num,0,sizeof(num)); mm.clear(); for( int i = 0; i < N; i++ ){ scanf("%d",&num[i]); mm[num[i]] = 1; } dfs(0); printf("%d\n",res); } return 0;}void dfs(int len){ if( len == 5 ){ int num1; int d,e; num1 = Lis[0]*100+Lis[1]*10+Lis[2]; d = Lis[3]; e = Lis[4]; if( test(d*num1,3) && test(e*num1,3) && test( (d*10+e)*num1,4 ) ){ //print(); res++; } return ; } for( int i = 0; i < N; i++ ){ Lis[len] = num[i]; dfs(len+1); } return ;}bool test(int x,int len){ int tmp; int flag = 0; while( x ){ flag++; tmp = x%10; if( mm[tmp] == 0 ){ return false; } x /= 10; } if( flag != len ){ return false; } return true;}////void print(){// for( int i = 0; i < N; i++ ){// printf("%d ",Lis[i]);// }// printf("\n");//}
0 0
- UASCO Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- Prime Cryptarithm
- USACO Prime Cryptarithm Accepted
- Prime Cryptarithm(USACO)
- USACO 1.3-Prime Cryptarithm
- 1.3.5 Prime Cryptarithm
- Section 1.4 Prime Cryptarithm
- [USACO] Prime Cryptarithm
- Prime Cryptarithm牛式
- USACO 1.3 Prime Cryptarithm
- 1.3.4 Prime Cryptarithm
- MapReduce:详解Shuffle过程
- js判断数据类型
- ROS中的CMakeLists.txt
- mysql客户端乱码问题解决,uuid使用方法
- java日期格式的Object类型转换成String类型的方法
- UASCO Prime Cryptarithm
- Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'
- 简单解决tomcat端口号被占用的问题
- HDU-1754-I Hate It-单点更新
- JAVA基础 - 删除字符串中指定字符串的方法
- 【TED】伟大的领袖如何激励行动
- 事务
- 《学习OpenCV》第四章课后题3-a
- USACO Combination Lock