题目链接  ECL-Final 2017 Problem D

题意  给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数

如果一个数小于等于$10^{15}$, 并且能被分割成一个至少有$3$项的递增等比数列(公比可以不为整数)

那么这个数是符合条件的。

比赛的时候我大概觉得这应该不是数位DP,是一个比较trick的枚举题。

但是我总感觉哪个地方不太对,或者说是没有写这道题的意识,一直瘫在那里。

今天AC了这个题之后真的后悔莫及,但是一点用都没有。

从至少有$3$项这个条件入手。

假设数列只有$3$项。

因为数列递增,所以第二项一定不超过$10^{5}$,

所以等比数列的公比

$\frac{q}{p} <= \frac{a_{2}}{a_{1}} <= a_{2} <= 10^{5}$

设第一项为$kp^{2}$, 第二项为$kpq$, 第三项为$kq^{2}$

那么$kpq <= 10^{5}$,即$pq <= 10^{5}$;

枚举符合条件的$p$和$q$,发现枚举量不超过$4*10^{5}$;

在这个基础上枚举$k$,然后求出整个数列,并考虑那些项数大于$3$的数列,

最后sort一下二分查找就可以了。

  1. #include <ctime>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. #define rep(i, a, b) for (int i(a); i <= (b); ++i)
  10. #define dec(i, a, b) for (int i(a); i >= (b); --i)
  11.  
  12. typedef long long LL;
  13.  
  14. const int N = 1e5 + 10;
  15.  
  16. LL a[N * 100];
  17. LL ten[20];
  18. LL l, r;
  19. int cnt = 0;
  20. int T, ca = 0;
  21.  
  22. int solve(LL x){ return upper_bound(a + 1, a + cnt + 1, x) - a - 1; }
  23.  
  24. inline int calc(LL x){
  25. int ret = 0;
  26. for (; x; x /= 10) ++ret;
  27. return ret;
  28. }
  29.  
  30. LL mer(LL x, LL y){ return x * ten[calc(y)] + y; }
  31.  
  32. int main(){
  33.  
  34. ten[0] = 1ll;
  35. rep(i, 1, 18) ten[i] = ten[i - 1] * 10ll;
  36.  
  37. rep(p, 1, 1e5){
  38. rep(q, p + 1, 1e5){
  39. if (1ll * p * q >= 1e5) break;
  40. if (__gcd(p, q) > 1) continue;
  41.  
  42. rep(k, 1, 1e5 / p / q){
  43. LL x = 1ll * k * p * p;
  44. LL y = 1ll * k * p * q;
  45. LL z = 1ll * k * q * q;
  46.  
  47. int cnt_len = calc(x) + calc(y) + calc(z);
  48. if (cnt_len > 15) break;
  49.  
  50. LL now = mer(mer(x, y), z);
  51. a[++cnt] = now;
  52.  
  53. while (true){
  54. if (calc(z) >= 9) break;
  55. if (z * z % y > 0) break;
  56. LL nw = z * z / y;
  57. int nwlen = calc(nw);
  58. if (cnt_len + nwlen > 15) break;
  59. cnt_len += nwlen;
  60. now = mer(now, nw);
  61. a[++cnt] = now;
  62. y = z;
  63. z = nw;
  64. }
  65. }
  66. }
  67. }
  68.  
  69. sort(a + 1, a + cnt + 1);
  70. scanf("%d", &T);
  71. while (T--){
  72. scanf("%lld%lld", &l, &r);
  73. printf("Case #%d: %d\n", ++ca, solve(r) - solve(l - 1));
  74. }
  75.  
  76. return 0;
  77. }

Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)的更多相关文章

  1. Codeforces Gym 101194C Mr. Panda and Strips(2016 EC-Final,区间DP预处理 + 枚举剪枝)

    题目链接  2016 EC-Final 题意  现在要找到数列中连续两个子序列(没有公共部分).要求这两个子序列本身内部没有重复出现的数.   求这两个子序列的长度的和的最大值. 首先预处理一下.令$ ...

  2. Gym 101194F Mr. Panda and Fantastic Beasts

    #include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...

  3. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  4. 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    先反复地扫(不超过n次),把所有可以确定唯一取法的给确定下来. 然后对于剩下的不能确定的,跑2-SAT.输出可行解时,对于a和¬a,如果a所在的强连通分量序号在¬a之前,则取a,否则不取a.如果a和¬ ...

  5. hdu6007 Mr. Panda and Crystal 最短路+完全背包

    /** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...

  6. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  7. H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)

    Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

随机推荐

  1. Jenkins拾遗--第四篇-适当的让构建失败

    问题的引出: 有一段我们的前端构建总会现git上分支名称中的版本号和工程里的版本号不一致的问题:这样会导致构一个问题:构建后的产品名称叫做1.1,但是进入app的关于页面,看到的版本还是1.0.这会让 ...

  2. 《Cracking the Coding Interview》——第4章:树和图——题目1

    2014-03-19 03:30 题目:判断一个二叉树是否为平衡二叉树,即左右子树高度相差不超过1. 解法:递归算高度并判断即可. 代码: // 4.1 Implement an algorithm ...

  3. Bit与Byte的区别

    在工作中遇到一些概念模糊的地方, 需要记住了bit意为“位”或“比特”,是计算机运算的基础: byte意为“字节”,是计算机文件大小的基本计算单位: 说到usb2.0标准接口传输速率.许多人都将“48 ...

  4. PyCharm 解决有些库(函数)没有代码提示

    问题描述: 如图,当输入 im. 没有智能提示第三库相应的函数或其他提示. 解决方案: python是动态强类型语言,IDE无法判断Image.open("panda.png")的 ...

  5. appium-在页面点击一下处理(一般处理提示蒙层)

    在写用例的时候,经常会发现某些第一次进去的页面会有一个蒙层提示.我们只有处理掉这个蒙层,才能继续我们的用例: 这边我们使用的是TouchAction的tap方法 TouchAction action ...

  6. 性能测试之siege

    一.siege介绍 Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数 ...

  7. 每个套接字地址error

    套接字问题 1 netstat -aon|findstr 5037   2 根据pid,查询占用端口的应用,这里的pid为 8672,查询命令如图 3 杀死对应的PID,taskkill /pid 8 ...

  8. postman导出excel出现response

    https://jingyan.baidu.com/article/915fc414559b4351394b2084.html

  9. Python全栈工程师(递归函数、闭包)

    ParisGabriel            每天坚持手写  一天一篇  决定坚持几年 全栈工程师     Python人工智能从入门到精通 函数式编程: 是指用一系列函数解决问题 每一个函数完成细 ...

  10. class内部处理

    class A { public: int foo( ) { return val ; } static int staFun( ) { return staVal ; } static int st ...