UVa 10396 - Vampire Numbers (暴力)

题意

计算n位的吸血鬼数有几个。

满足以下条件的成为吸血鬼数。

  1. v = xy, xy中的数合起来正好和v中的一样。
  2. xy不能同时有后缀0

思路

一开始打了个表,不过太大了,不让交。然后就直接暴力了。

代码

  1. #include <cstdio>
  2. #include <stack>
  3. #include <set>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <functional>
  9. #include <cstring>
  10. #include <algorithm>
  11. #include <cctype>
  12. #include <string>
  13. #include <map>
  14. #include <iomanip>
  15. #include <cmath>
  16. #define LL long long
  17. #define ULL unsigned long long
  18. #define SZ(x) (int)x.size()
  19. #define Lowbit(x) ((x) & (-x))
  20. #define MP(a, b) make_pair(a, b)
  21. #define MS(arr, num) memset(arr, num, sizeof(arr))
  22. #define PB push_back
  23. #define F first
  24. #define S second
  25. #define ROP freopen("input.txt", "r", stdin);
  26. #define MID(a, b) (a + ((b - a) >> 1))
  27. #define LC rt << 1, l, mid
  28. #define RC rt << 1|1, mid + 1, r
  29. #define LRT rt << 1
  30. #define RRT rt << 1|1
  31. #define BitCount(x) __builtin_popcount(x)
  32. #define BitCountll(x) __builtin_popcountll(x)
  33. #define LeftPos(x) 32 - __builtin_clz(x) - 1
  34. #define LeftPosll(x) 64 - __builtin_clzll(x) - 1
  35. const double PI = acos(-1.0);
  36. const int INF = 0x3f3f3f3f;
  37. using namespace std;
  38. const double eps = 1e-8;
  39. const int MAXN = 10000 + 10;
  40. const int MOD = 1000007;
  41. const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
  42. typedef pair<int, int> pii;
  43. typedef vector<int>::iterator viti;
  44. typedef vector<pii>::iterator vitii;
  45. bool Check(int a, int b)
  46. {
  47. int vis[11], vvis[11];
  48. MS(vis, 0); MS(vvis, 0);
  49. int num = a * b;
  50. while (a)
  51. {
  52. int rem = a % 10;
  53. a /= 10;
  54. vis[rem]++;
  55. }
  56. while (b)
  57. {
  58. int rem = b % 10;
  59. b /= 10;
  60. vis[rem]++;
  61. }
  62. while (num)
  63. {
  64. int rem = num % 10;
  65. num /= 10;
  66. vvis[rem]++;
  67. }
  68. for (int i = 0; i < 10; i++)
  69. if (vis[i] != vvis[i]) return false;
  70. return true;
  71. }
  72. set<int> ans[10];
  73. int main()
  74. {
  75. const LL MAX = 1e10;
  76. int i, j;
  77. for (i = 10; i <= 99; i++)
  78. for (j = i; j <= 99; j++)
  79. {
  80. int num = i * j;
  81. if (num & 1) continue;
  82. if (i % 10 == 0 && j % 10 == 0) continue;
  83. if (Check(i, j)) ans[2].insert(num);
  84. }
  85. for (i = 100; i <= 999; i++)
  86. for (j = 100; j <= 999; j++)
  87. {
  88. int num = i * j;
  89. if (num > 100000000) continue;
  90. if (num & 1) continue;
  91. if (i % 10 == 0 && j % 10 == 0) continue;
  92. if (Check(i, j)) ans[3].insert(num);
  93. }
  94. for (i = 1000; i <= 9999; i++)
  95. for (j = i; j <= 9999; j++)
  96. {
  97. if (i % 10 == 0 && j % 10 == 0) continue;
  98. LL num = (LL)i * j;
  99. if (num > MAX) continue;
  100. if (num & 1) continue;
  101. if (Check(i, j)) ans[4].insert(num);
  102. }
  103. int n;
  104. while (~scanf("%d", &n))
  105. {
  106. int pos = n / 2;
  107. for (set<int>::iterator it = ans[pos].begin(); it != ans[pos].end(); it++)
  108. printf("%d\n", *it);
  109. puts("");
  110. }
  111. return 0;
  112. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值