[关闭]
@tenlee 2015-07-31T11:25:48.000000Z 字数 839 阅读 1623

HDU 5327 Olympiad(2015多校联合)

HDUOJ


题目链接

戳我

题目大意

计算区间 LR内每个数的 每位 是由不同的数 构成的 个数
即 一个区间内的每个数 它的个位,十位.....是不同的数字构成的个数

样例解释

解题思路

简单题. 但是暴力枚举肯定会超时的.但是比赛的时候数据比较弱,可以水过去.....
可以先预处理每一个前缀有多少个即可

代码

  1. //Author LJH
  2. //www.cnblogs.com/tenlee
  3. #include <cstdio>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cctype>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #define clc(a, b) memset(a, b, sizeof(a))
  14. using namespace std;
  15. const int inf = 0x3f;
  16. const int INF = 0x3f3f3f3f;
  17. const int maxn = 1e5+5;
  18. int a[maxn], b[maxn], ha[20];
  19. bool judge(int n)
  20. {
  21. clc(ha, 0);
  22. int x, y;
  23. while(n)
  24. {
  25. x = n % 10;
  26. n = n / 10;
  27. if(ha[x]) return false;
  28. else ha[x] = 1;
  29. }
  30. return true;
  31. }
  32. void Init()
  33. {
  34. clc(b, 0);
  35. a[0] = 1;
  36. for(int i = 1; i < maxn; i++)
  37. {
  38. a[i] = a[i-1];
  39. if(judge(i))
  40. {
  41. b[i] = 1;
  42. a[i]++;
  43. }
  44. }
  45. }
  46. int main()
  47. {
  48. Init();
  49. int T;
  50. int x, y, ans;
  51. scanf("%d", &T);
  52. while(T--)
  53. {
  54. scanf("%d %d", &x, &y);
  55. ans = a[y] - a[x];
  56. if(b[x])
  57. {
  58. ans++;
  59. //puts("hehe");
  60. }
  61. printf("%d\n", ans);
  62. }
  63. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注