[暴力]uva-725-Division

https://vjudge.net/problem/UVA-725

暴力入门经典题
题意:两个整数(等于5位)相除等于 给定的n
输出所有可能 要求这两个整数每位各不相同(0123456789全有)
这个题用暴力枚举做 做法通过优雅的暴力
a/b=n -> a=b*n
我们枚举a b a从1234开始枚举 而b*n最大就是98765

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int maxn = 1e3 + 5;

int a, b, n, vis[10];

inline bool check(int m) {
for (int i = 0; i < 5; i++) {
if (vis[m % 10]) return 0;
else vis[m % 10]++, m /= 10;
}
}

int main() {
int st = 0;
while (~scanf(“%d”, &n) && n) {
if (st) putchar(‘\n’);
else st = 1;
int ok = 0;
for (b = 1234; (a = n * b) < 98765; b++) {
memset(vis, 0, sizeof(vis));
if (check(a) && check(b)) printf(“%05d / %05d = %d\n”, a, b, n), ok = 1;
}
if (!ok) printf(“There are no solutions for %d.\n”, n);
}
return 0;
}


[暴力]uva-725-Division
https://47.97.0.163/2019/07/30/暴力uva-725-division/
作者
John Doe
发布于
2019年7月30日
许可协议