暴力枚举 UVA 725 Division

 

题目传送门

 1 /*  2  暴力:对于每一个数都判断,是否数字全都使用过一遍  3 */  4 #include <cstdio>  5 #include <iostream>  6 #include <algorithm>  7 #include <cmath>  8 #include <cstring>  9 #include <string> 10 #include <map> 11 #include <set> 12 #include <queue> 13 using namespace std; 14 15 const int MAXN = 1e4 + 10; 16 const int INF = 0x3f3f3f3f; 17 int vis[10]; 18 19 bool ok(int x, int y) 20 { 21 memset (vis, 0, sizeof (vis)); 22 for (int i=1; i<=5; ++i) 23  { 24 vis[x%10]++; vis[y%10]++; 25 if (vis[x%10] > 1 || vis[y%10] > 1) return false; 26 x /= 10; y /= 10; 27  } 28 29 return true; 30 } 31 32 int main(void) //UVA 725 Division 33 { 34 //freopen ("UVA_725.in", "r", stdin); 35 36 int n, cnt = 0; 37 while (scanf ("%d", &n) == 1) 38  { 39 if (n == 0) break; 40 if (cnt++) puts (""); 41 42 int one = 0; 43 for (int i=1234; i<=100000/n; ++i) 44  { 45 if (i * n > 98765) break; 46 if (ok (i, i*n) == true) 47  { 48 printf ("%05d / %05d = %d\n", n*i, i, n); one++; 49  } 50  } 51 52 if (!one) printf ("There are no solutions for %d.\n", n); 53  } 54 55 return 0; 56 } 57 58 59 /* 60 There are no solutions for 61. 61 */

 

你可能感兴趣的:(visio)