首页 > 其他 > 详细

usaco Prime Cryptarithm

时间:2015-08-27 14:51:03      阅读:127      评论:0      收藏:0      [点我收藏+]
/*
ID: modengd1
PROG: crypt1
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <memory.h>
using namespace std;
int input[10],N;
bool tag[10000];
int counter()
{

    int ans=0;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            for(int k=0;k<N;k++)
            {
                for(int h=0;h<N;h++)
                {
                    int temp1=input[i]*100+input[j]*10+input[k];
                    int temp2=temp1*input[h];
                    if(temp2>999)
                        continue;
                    if(tag[temp2])
                    for(int m=0;m<N;m++)
                    {
                        int temp5=temp1*input[m];
                        if(temp5>999)
                            continue;
                        if(tag[temp5])
                        {
                            if((temp2*10+temp5)>9999)
                                continue;
                            if(tag[temp2*10+temp5])
                            {
                                ans++;
                            }
                        }
                    }
                }
            }
        }
    }
    return ans;
}
int main()
{
    freopen("crypt1.in","r",stdin);
    freopen("crypt1.out","w",stdout);
    memset(tag,false,sizeof(tag));
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&input[i]);
    }
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            for(int k=0;k<N;k++)
            {
                int temp3=input[i]*100+input[j]*10+input[k];
                tag[temp3]=true;
                for(int m=0;m<N;m++)
                {
                    int temp4=temp3*10+input[m];
                    tag[temp4]=true;
                }
            }
        }
    }
    cout<<counter()<<endl;
    return 0;
}

  

usaco Prime Cryptarithm

原文:http://www.cnblogs.com/modengdubai/p/4763192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!