题目链接:https://ac.nowcoder.com/acm/contest/70/B

题目大意:

  略

分析:

  先DFS求出所有幸运数,然后暴力即可

代码如下:

  1. #pragma GCC optimize("Ofast")
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
  6. #define Rep(i,n) for (int i = 0; i < (n); ++i)
  7. #define For(i,s,t) for (int i = (s); i <= (t); ++i)
  8. #define rFor(i,t,s) for (int i = (t); i >= (s); --i)
  9. #define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
  10. #define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
  11. #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
  12. #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
  13.  
  14. #define pr(x) cout << #x << " = " << x << " "
  15. #define prln(x) cout << #x << " = " << x << endl
  16.  
  17. #define LOWBIT(x) ((x)&(-x))
  18.  
  19. #define ALL(x) x.begin(),x.end()
  20. #define INS(x) inserter(x,x.begin())
  21.  
  22. #define ms0(a) memset(a,0,sizeof(a))
  23. #define msI(a) memset(a,inf,sizeof(a))
  24. #define msM(a) memset(a,-1,sizeof(a))
  25.  
  26. #define pii pair<int,int>
  27. #define piii pair<pair<int,int>,int>
  28. #define MP make_pair
  29. #define PB push_back
  30. #define ft first
  31. #define sd second
  32.  
  33. template<typename T1, typename T2>
  34. istream &operator>>(istream &in, pair<T1, T2> &p) {
  35. in >> p.first >> p.second;
  36. return in;
  37. }
  38.  
  39. template<typename T>
  40. istream &operator>>(istream &in, vector<T> &v) {
  41. for (auto &x: v)
  42. in >> x;
  43. return in;
  44. }
  45.  
  46. template<typename T1, typename T2>
  47. ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
  48. out << "[" << p.first << ", " << p.second << "]" << "\n";
  49. return out;
  50. }
  51.  
  52. typedef long long LL;
  53. typedef unsigned long long uLL;
  54. typedef pair< double, double > PDD;
  55. typedef set< int > SI;
  56. typedef vector< int > VI;
  57. const double EPS = 1e-;
  58. const int inf = 1e9 + ;
  59. const LL mod = 1e9 + ;
  60. const int maxN = 1e5 + ;
  61. const LL ONE = ;
  62.  
  63. LL l, r, ans;
  64. LL lucky[], n;
  65.  
  66. // 求所有幸运数
  67. inline void dfs(LL x, int cnt) {
  68. if(cnt > ) return;
  69. lucky[n++] = x;
  70. dfs(x* + , cnt + );
  71. dfs(x* + , cnt + );
  72. }
  73.  
  74. int main(){
  75. INIT();
  76. cin >> l >> r;
  77. lucky[n++] = ;
  78. dfs(, );
  79. sort(lucky, lucky + n);
  80.  
  81. int j = lower_bound(lucky, lucky + n, l) - lucky;
  82.  
  83. while(l <= r) {
  84. ans += (min(lucky[j], r) - l + ) * lucky[j];
  85. l = lucky[j++] + ;
  86. }
  87.  
  88. cout << ans << endl;
  89. return ;
  90. }
  91.  
  92. /*
  93. 1 1000000000
  94. 1394672350065645019
  95.  
  96. 1 1000
  97. 1397683
  98.  
  99. 447 447477474
  100. 168389348342066109
  101.  
  102. 1 436278568
  103. 163403864955643707
  104.  
  105. 1 4328955
  106. 16190029435407
  107.  
  108. 4328956 4444444
  109. 513284393116
  110.  
  111. 4328956 436278568
  112. 163387674926208300
  113.  
  114. 2354 543262
  115. 231508617956
  116.  
  117. 999999999 1000000000
  118. 8888888888
  119. */

牛客练习赛13B 幸运数字2的更多相关文章

  1. 牛客练习赛13D 幸运数字4

    题目链接:https://ac.nowcoder.com/acm/contest/70/D 题目大意: 略 分析: 注意到12! < 10^9 < 13!,于是当n > 13时,第k ...

  2. 牛客提高D2t2 幸运数字考试

    分析 预处理出所有合法数字 然后直接lower_bound查询即可 代码 #include<iostream> #include<cstdio> #include<cst ...

  3. 牛客练习赛48 C 小w的糖果 (数学,多项式,差分)

    牛客练习赛48 C 小w的糖果 (数学,多项式) 链接:https://ac.nowcoder.com/acm/contest/923/C来源:牛客网 题目描述 小w和他的两位队友teito.toki ...

  4. 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)

    牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...

  5. 牛客练习赛53 D 德育分博弈政治课 (思维建图,最大流)

    牛客练习赛53 D德育分博弈政治课 链接:https://ac.nowcoder.com/acm/contest/1114/D来源:牛客网 题目描述 德育分学长最近玩起了骰子.他玩的骰子不同,他的骰子 ...

  6. 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D

    目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...

  7. 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B

    牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...

  8. 牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A

    牛客练习赛31 D 神器大师泰兹瑞与威穆 https://ac.nowcoder.com/acm/contest/218/D 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26214 ...

  9. 最小生成树--牛客练习赛43-C

    牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 ​ 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...

随机推荐

  1. postgresql + mybatis insert主键自增方法

    postgresql + mybatis插入记录时设置自增主键方法: 一.数据库设置主键自增 1.数据库中id字段选择serial4类型后,会在默认值中生成 nextval('app_id_seq': ...

  2. Python3爬虫 利用百度地图api得到城市经纬度

    有2种方式,第一种是利用urllib , 方法1:利用urllib , 先把url 转成urlcode,然后读取网页,读到网页再用json读取内容,比较麻烦. 可以在浏览器输入,看一下格式. http ...

  3. 隔离 docker 容器中的用户-------分享链接

    https://www.cnblogs.com/sparkdev/p/9614326.html

  4. python笔记31-使用ddt报告出现dict() -> new empty dictionary dict(mapping) 问题解决

    使用ddt框架生成html报告的时候,出现:dict() -> new empty dictionary dict(mapping) -> new dictionary initializ ...

  5. 7-EL表达式和JSTL表达式

    引入jar包 一.EL表达式1.表达式语言,用于jsp网页中获取和计算数据2.语法:${表达式}3.用于取值:可以从pageContext,request,session,application这些域 ...

  6. Android APP性能测试笔记(二)

    (5)FPS   每秒传输帧数(Frames Per Second),每秒钟帧数愈多,所显示的动作就会愈流畅,标准的fps是60 帧数就是在1秒钟时间里传输的图片的量,也可以理解为图形处理器每秒钟能够 ...

  7. Linux 查看物理 CPU、内存信息

    可以通过本文如下方法查看云服务器 Linux 系统的 CPU.内存相关信息: 说明: 总核数 = 物理CPU个数 × 每颗物理CPU的核数 总逻辑CPU数 = 物理CPU个数 × 每颗物理CPU的核数 ...

  8. Luogu P1776 宝物筛选_NOI导刊2010提高(02)(多重背包模版)

    传送门 多重背包板子题, 多重背包就是每种东西有好几个,可以把它拆分成一个一个的01背包 优化:二进制拆分(拆成1+2+4+8+16+...) 比如18=1+2+4+8+3,可以证明18以内的任何数都 ...

  9. mac 下利用AndroidStudio APK获取签名信息

    注:网上没找到特别好的.不是xxx.keystore 就是debug.keystore 而真正去找这些目录的时候系统就会提示没有这个秘钥库文件.所以就悲剧了 下面附上快速查看APK签名信息的方法(SH ...

  10. Linux并发与同步专题 (4) Mutex互斥量

    关键词:mutex.MCS.OSQ. <Linux并发与同步专题 (1)原子操作和内存屏障> <Linux并发与同步专题 (2)spinlock> <Linux并发与同步 ...