UVA 725

来源:互联网 发布:37传奇霸业龙脉数据 编辑:程序博客网 时间:2024/06/03 19:43

题目大意:输入n,如果存在输出形如 abcde / fghij = n的形式。abcdefghij是0~9的某种排序。存在前导0。不存在则输出提示。

解题思路:枚举fghij。求出abcde,是否没有重复的,且数的位数没错。要做一些限定,否则会超时。

ac代码:

#include <iostream>#include <set>using namespace std;int n, temp, sum, count=0;set <int>se;int main(){while (scanf("%d", &n)!=EOF && n){sum = 0;if (count)printf("\n");count++;for (int i=1234; i<100000; i++){temp = n * i;if (temp > 98765)continue;for (int j=0,cnt=1; j<5; j++,cnt*=10)se.insert(i/cnt%10);for (int j=0,cnt=1; j<5; j++,cnt*=10)se.insert(temp/cnt%10);if (se.size() == 10){sum++;printf("%05d / %05d = %d\n", temp, i, n);}se.clear();}if (!sum)printf("There are no solutions for %d.\n", n);}return 0;}
原创粉丝点击