# UVa 725 Division

UVa题目惯例小心输出格式。这个题是简单的整数枚举。联系 UVa 10976可以发现枚举也是有技巧的，往往只需部分枚举，其他不定元可以通过部分枚举的值推算出来，这道题就是如此。题意本身非常简单了，给一个整数n，求0~9五五分的两个整数u、v，使得成立u / v = n

//  Created by wander on 16/6/1.
//  UVa725 Division
//  类型：枚举-整数枚举

#include "bits/stdc++.h"
using namespace std;

int n, cnt;
int EnumList[100050], s;
bool Used[10], flag, blank;

void Init(int d) {
if (d >= 5) { EnumList[cnt++] = s; return; }
for (int i = 0; i < 10; i += 1) {
if (Used[i]) continue;
Used[i] = true;
s = s * 10 + i;
Init(d + 1);
s = s / 10;
Used[i] = false;
}
}

void Check(int n, int i) {
memset(Used, false, sizeof(Used));
int u = EnumList[i];
int v = n * u;
if (v > 98765) return;
if (v < 10000) Used[0] = true;
if (u < 10000) { if (Used[0]) return; else Used[0] = true; }
for (int ucopy = u; ucopy != 0; ucopy /= 10)
if (Used[ucopy % 10]) return; else Used[ucopy % 10] = true;
for (int vcopy = v; vcopy != 0; vcopy /= 10)
if (Used[vcopy % 10]) return; else Used[vcopy % 10] = true;
flag = true;
printf("%05d / %05d = %d\n", v, u, n);
}

int main() {
#ifdef DEBUG
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
// input and pre-process
Init(0);
while (~scanf("%d", &n) && n) {
// work
if (!blank) blank = true; else putchar('\n');
flag = false;
for (int i = 0; i < cnt; i += 1) Check(n, i);
if (!flag) printf("There are no solutions for %d.\n", n);
}
return 0;
}

//  Created by wander on 16/5/27.
//  UVa725 Division
//  类型：枚举-整数枚举

#include "bits/stdc++.h"
using namespace std;

int n, cnt;
string EnumList[100050], s;
bool Used[10], flag, blank;

void Init(int d) {
if (d >= 5) { EnumList[cnt++] = s; return; }
for (int i = 0; i < 10; i += 1) {
if (Used[i]) continue;
Used[i] = true;
s.append(1, '0' + i);
Init(d + 1);
s.erase(s.end() - 1);
Used[i] = false;
}
}

void Check(int n, int i) {
string u = EnumList[i];
string v = to_string(n * stoi(u));
set<char> e;
if (v.size() > 5) return;
if (v.size() <= 4) v += "0";
if (u.size() <= 4) u += "0";
for (int i = 0, sup = (int)u.size(); i < sup; i += 1)
if (e.count(u[i])) return; else e.insert(u[i]);
for (int i = 0, sup = (int)v.size(); i < sup; i += 1)
if (e.count(v[i])) return; else e.insert(v[i]);
flag = true;
printf("%s / %s = %d\n", v.c_str(), u.c_str(), n);
}

int main() {
#ifdef DEBUG
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
// input and pre-process
Init(0);
while (~scanf("%d", &n) && n) {
// work
if (!blank) blank = true; else putchar('\n');
flag = false;
for (int i = 0; i < cnt; i += 1) Check(n, i);
if (!flag) printf("There are no solutions for %d.\n", n);
}
return 0;
}


• 本文已收录于以下专栏：

## UVa725 Division(暴力)

UVa725 Division (暴力)

## UVA - 725 Division （暴力枚举）

Division  Write a program that finds and displays all pairs of 5-digit numbers thatbetwee...

## uva 725 Division

uva 725  Division  Write a program that finds and displays all pairs of 5-digit numbers that ...

## UVA_725: Division

Description Write a program that finds and displays all pairs of 5-digit numbers thatbetween them u...

## UVA - 725 Division

Division  Write a program that finds and displays all pairs of 5-digit numbers that bet...
• kun768
• 2014年12月12日 23:05
• 416

## UVa - 725 - Division(暴力枚举)

#include #include using namespace std; int num1[10]; int num2[10]; // 12345 012345 bool check(int a,...

举报原因： 您举报文章：UVa 725 Division 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)