usaco Prime Cryptarithm

来源:互联网 发布:mac 思维导图 编辑:程序博客网 时间:2024/06/06 04:35

小暴力,题意有点坑,看了别人的才完全明白。

题意:给你n个数。判断n个数能够形成多少种成立的算式。算式成立的标准是,*号必须由n个数代替。当然还有最坑的The partial products must be three digits long, even though the general case (see below) might have four digit partial products. 计算过程中间数必须是3位。

/**TASK: crypt1LANG: C++ID: DickensTone**/#include<cstdio>#include<cstring>#include<fstream>int num;bool no(int x){    //printf("%d %d\n", x, num);    //printf("-------------\n");    while(x)    {        int t = x % 10;        //printf("%d\n", t);        if(!(num & (1 << t))) return true;        x = x / 10;    }    return false;}int main(){    freopen("crypt1.in", "r", stdin);    freopen("crypt1.out", "w", stdout);    int n;    while(scanf("%d", &n) == 1)    {        num = 0;        int cnt = 0;        for(int i = 0; i < n; i++)        {            int t;            scanf("%d", &t);            //printf("%d\n", num);            num = num | (1 << t);        }        //printf("%d\n", num);        for(int i = 101; i < 1000; i++)        {            if(no(i)) continue;            for(int j = 11; j < 100 && i * j <= 9999; j++)            {                if(no(j)) continue;                bool ok = true;                int t2 = (j % 10) * i, t1 = (j / 10) * i;                if(t1 >= 1000 || t2 >= 1000) continue;                int t = t1 * 10 + t2;                if(no(t1) || no(t2) || no(t)) ok = false;                if(ok)                {                    cnt++;                    //printf("%d %d\n", t1, t2);                }            }        }        printf("%d\n", cnt);    }    return 0;}


原创粉丝点击