uva 471 - Magic Numbers(枚举技巧)
2013-12-21 20:12
417 查看
Magic Numbers |
and
such
that:
neither
nor
have
any digits repeated; and
, where N is a given integer;
Input and Output
The input file consist a integer at the beginning indicating the number of test case followed by a blank line. Each test case consists of one line of input containing N. Two input are separatedby a blank line.
For each input the output consists of a sequence of zero or more lines each containing
/
= N,
where
and N are the integers described above. When there are two or more solutions, sort them by increasing numerator
values. Two consecutive output set will separated by a blank line.
Sample Input
1 1234567890
Sample Output
1234567890 / 1 = 1234567890 2469135780 / 2 = 1234567890 4938271560 / 4 = 1234567890 6172839450 / 5 = 1234567890 8641975230 / 7 = 1234567890 9876543120 / 8 = 1234567890
题意: 给一个n,求出有几种s1 / s2方式去得到他,并且s1,s2必须不能有重复的数字。
思路: 感觉这题题目不清不楚啊。没有n的范围啊。如果n很小那么情况会是非常多的肯定就超时了。。说明没有这样的数字,N应该都是很大的。所以去枚举到9876543210就结束了。然后去判断有没有重复的数字。
代码:
#include <stdio.h>
#include <string.h>
const long long MAXN = 9876543210;
int T, vis[10];
long long n, num;
bool check(long long num) {
memset(vis, 0, sizeof(vis));
while (num) {
if (vis[num % 10]) return false;
vis[num % 10]++;
num /= 10;
}
return true;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld", &n);
for (long long i = 1; i <= MAXN; i ++) {
num = n * i;
if (num > MAXN) break;
if (check(num) && check(i))
printf("%lld / %lld = %lld\n", num, i, n);
}
if (T) printf("\n");
}
return 0;
}
相关文章推荐
- UVa 471 Magic Numbers (枚举)
- UVA 471 Magic Numbers(枚举)
- uva 1382 Distant Galaxy(离散化+枚举技巧)
- UVA471- Magic Numbers
- UVA 1326 - Jurassic Remains(技巧枚举+位运算)
- uva 1618(枚举技巧)
- UVa 471 - Magic Numbers
- UVA - 471 Magic Numbers
- uva - Magic Numbers(枚举、位运算)
- (UVA - 10976)Fractions Again?!(技巧,暴力枚举)
- UVA 11012 - Cosmic Cabbages(枚举技巧)
- UVa:471 Magic Numbers
- uva 11752 - The Super Powers(数论+枚举技巧)
- UVA 10730 - Antiarithmetic?(技巧枚举)
- UVA-1312 Cricket Field (技巧枚举)
- uva 12716 GCD XOR (数论)枚举技巧(筛法) + 思维
- uva 471 - Magic Numbers(搜索)
- UVA 10483 - The Sum Equals the Product (枚举技巧)
- UVA 1481 - Genome Evolution(枚举技巧)
- UVa229 - Scanner(枚举技巧)