UVA - 725 Division

来源:互联网 发布:最好手机电视直播软件 编辑:程序博客网 时间:2024/06/18 04:34

题目链接:

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

这里写图片描述
这里写图片描述

暴力搜索。。。

wrong wrong wrong!!!没完了。。

/*************************************************************************    > File Name: UVa_725.cpp    > Author: dulun    > Mail: dulun@xiyoulinux.org    > Created Time: 2016年03月18日 星期五 20时44分13秒 ************************************************************************/#include<iostream>#include<stdio.h>#include<cstring>#include<cstdlib>#include<algorithm>#define LL long longusing 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;}
0 0
原创粉丝点击