uva 10396 - Vampire Numbers(暴力)
2014-01-08 14:25
357 查看
题目链接:uva 10396 - Vampire Numbers
题目大意:输入n,找出为数为n的吸血鬼数字。吸血鬼数字即偶数,并且可以拆分成两个不同为10的倍数的数,相乘为它本身。
解题思路:枚举拆分后的两个数,然后判断。
#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
const int N = 6;
const int tmp
= {0, 1, 10, 100, 1000, 10000};
int n, rec
;
set<int> v
;
bool judge(int a, int b) {
int c[10], s = a * b;
memset(c, 0, sizeof(c));
while (a) {
c[a%10]++; a /= 10;
}
while (b) {
c[b%10]++; b /= 10;
}
while (s) {
c[s%10]--; s /= 10;
}
for (int i = 0; i < 10; i++) if (c[i] != 0) return false;
return true;
}
void solve() {
int k = n / 2;
if (rec[k] == 0) {
for (int i = tmp[k]; i < tmp[k+1]; i++) {
for (int j = i; j < tmp[k+1]; j++) {
if (i % 10 == 0 && j % 10 == 0) continue;
if (i % 2 && j % 2) continue;
if (judge(i, j)) v[k].insert(i * j);
}
}
}
rec[k] = 1;
for (set<int>::iterator i = v[k].begin(); i != v[k].end(); i++)
printf("%d\n", *i);
printf("\n");
}
int main() {
memset(rec, 0, sizeof(rec));
while (scanf("%d", &n) == 1) {
solve();
}
return 0;
}
题目大意:输入n,找出为数为n的吸血鬼数字。吸血鬼数字即偶数,并且可以拆分成两个不同为10的倍数的数,相乘为它本身。
解题思路:枚举拆分后的两个数,然后判断。
#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
const int N = 6;
const int tmp
= {0, 1, 10, 100, 1000, 10000};
int n, rec
;
set<int> v
;
bool judge(int a, int b) {
int c[10], s = a * b;
memset(c, 0, sizeof(c));
while (a) {
c[a%10]++; a /= 10;
}
while (b) {
c[b%10]++; b /= 10;
}
while (s) {
c[s%10]--; s /= 10;
}
for (int i = 0; i < 10; i++) if (c[i] != 0) return false;
return true;
}
void solve() {
int k = n / 2;
if (rec[k] == 0) {
for (int i = tmp[k]; i < tmp[k+1]; i++) {
for (int j = i; j < tmp[k+1]; j++) {
if (i % 10 == 0 && j % 10 == 0) continue;
if (i % 2 && j % 2) continue;
if (judge(i, j)) v[k].insert(i * j);
}
}
}
rec[k] = 1;
for (set<int>::iterator i = v[k].begin(); i != v[k].end(); i++)
printf("%d\n", *i);
printf("\n");
}
int main() {
memset(rec, 0, sizeof(rec));
while (scanf("%d", &n) == 1) {
solve();
}
return 0;
}
相关文章推荐
- UVA - 10396 Vampire Numbers 暴力+打表
- UVA 10396 - Vampire Numbers(暴力打表)
- UVa 10396 - Vampire Numbers (暴力)
- Vampire Numbers - UVALive 5779 暴力打表
- The 70th problem,UVa10396 Vampire Numbers
- The 70th problem,UVa10396 Vampire Numbers
- UVA - 10396(简单暴力)
- UVa10396 - Vampire Numbers
- UVA - 10396 Vampire Numbers
- UVa10396 - Vampire Numbers
- uva 10396——Vampire Numbers
- uva 646 - The Gourmet Club(暴力)
- uva 11598 - Optimal Segments(DP+暴力)
- 【UVA】10012 - How Big Is It?(暴力)
- UVa 10318 Security Panel 解题报告(暴力,中途相遇法)
- UVA 10729 - Treequivalence(暴力枚举)
- UVa 11464-Even Parity 偶数矩阵-bitmask+暴力
- UVALive 6924 暴力
- UVA - 10487 Closest Sums 暴力
- uva 10245 The Closest Pair Problem (暴力+剪枝)