UVA - 725 Division

题目链接:

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35442


暴力搜索。。。

wrong wrong wrong!!!没完了。。

/************************************************************************* > File Name: UVa_725.cpp > Author: dulun > Mail: [email protected] > Created Time: 2016年03月18日 星期五 20时44分13秒 ************************************************************************/

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;

const int N = 50086;

bool check(int a, int b)
{
    if(b >98765) return 0;
    int v[15] = {0};
    memset(v, 0, sizeof(v));
    if(a < 10000) v[0] = 1;
    while(a)
    {
        v[a%10] = 1;
        a /= 10;
    }
    while(b)
    {
        v[b%10] = 1;
        b /= 10;
    }
    int sum = 0;
    for(int i = 0; i < 10; i++)
    {
        sum += v[i];
    }
    return (sum == 10);

}

int main()
{
    int n, t = 0;
    while(~scanf("%d", &n) && n)
    {
        if(t++) printf("\n");
        int flag = 0;
        for(int i = 1234; i < 50000; i++)
        {
            if(check(i, i*n))
            {
                printf("%05d / %05d = %d\n", i*n, i, n);
                flag++;
            }
        }
        if(flag == 0) printf("There are no solutions for %d.\n", n);
    }


    return 0;
}

你可能感兴趣的:(搜索)