方法:暴力枚举。
AC代码:
#include <iostream> #include <iomanip> #include <string> #include <cstring> #include <cstdio> #include <queue> #include <stack> #include <algorithm> #include <cmath> #include <ctime> using namespace std; const long long int maxn = 9876543210; inline bool check(long long x) { int i = 0, cnt = 0; while (x) { i = 1 << (x % 10); if (cnt & i) return false; cnt |= i; x /= 10; } return true; } int main() { int t = 0; cin >> t; while (t--) { long long int x = 0, a = 0, b = 0; cin >> x; for (b = 1; b < maxn; b++) { a = b * x; if (a > maxn) break; else if (check(a) && check(b)) cout << a << " / " << b << " = " << x << endl; } if (t) cout << endl; } return 0; }参考 :http://tech.ddvip.com/2013-12/1386686677206922.html 位运算的方法非常厉害不得不佩服,并且程序比想象的快了非常多。。但是不理解是硬伤,姑且先这样记住吧!
uva - Magic Numbers(枚举、位运算),布布扣,bubuko.com
原文:http://blog.csdn.net/u013545222/article/details/24328261