题目链接  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一下二分查找就可以了。

#include <ctime>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) typedef long long LL; const int N = 1e5 + 10; LL a[N * 100];
LL ten[20];
LL l, r;
int cnt = 0;
int T, ca = 0; int solve(LL x){ return upper_bound(a + 1, a + cnt + 1, x) - a - 1; } inline int calc(LL x){
int ret = 0;
for (; x; x /= 10) ++ret;
return ret;
} LL mer(LL x, LL y){ return x * ten[calc(y)] + y; } int main(){ ten[0] = 1ll;
rep(i, 1, 18) ten[i] = ten[i - 1] * 10ll; rep(p, 1, 1e5){
rep(q, p + 1, 1e5){
if (1ll * p * q >= 1e5) break;
if (__gcd(p, q) > 1) continue; rep(k, 1, 1e5 / p / q){
LL x = 1ll * k * p * p;
LL y = 1ll * k * p * q;
LL z = 1ll * k * q * q; int cnt_len = calc(x) + calc(y) + calc(z);
if (cnt_len > 15) break; LL now = mer(mer(x, y), z);
a[++cnt] = now; while (true){
if (calc(z) >= 9) break;
if (z * z % y > 0) break;
LL nw = z * z / y;
int nwlen = calc(nw);
if (cnt_len + nwlen > 15) break;
cnt_len += nwlen;
now = mer(now, nw);
a[++cnt] = now;
y = z;
z = nw;
}
}
}
} sort(a + 1, a + cnt + 1);
scanf("%d", &T);
while (T--){
scanf("%lld%lld", &l, &r);
printf("Case #%d: %d\n", ++ca, solve(r) - solve(l - 1));
} return 0;
}

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. GCD那些事儿

    GCD GCD,全名Grand Central Dispatch,中文名郭草地,是基于C语言的一套多线程开发API,一听名字就是个狠角色,也是目前苹果官方推荐的多线程开发方式.可以说是使用方便,又不失 ...

  2. [译]在python中如何有效的比较两个无序的列表是否包含完全同样的元素(不是set)?

    原文来源: https://stackoverflow.com/questions/7828867/how-to-efficiently-compare-two-unordered-lists-not ...

  3. 第二章 Internet 地址结构

    注意: 这个系列的博客只是为了巩固我学习的知识,参考的价值不是很大,如果需要,请转到http://www.cnblogs.com/ZCplayground/p/7764436.html Interne ...

  4. SystemTap 用法

    SystemTap需要内核符号表: http://ddebs.ubuntu.com/pool/main/l/linux/ 基本语法: next对应C中的return,中途返回: 今晚遗留了两个问题: ...

  5. CSLM 配置粗解

    CSLM工具(continuous space language model toolkit)用于训练NNLM,支持SRILM.KENLM(默认)语言模型工具,CUDA加速,CSTM统计机器翻译. 本 ...

  6. chrome性能指标(TTFB,TTSR,TTDC,TTFL)

    1.TTFB (Time To First Byte) 是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间. 注意: ...

  7. [学习笔记]Senparc.CO2NET 缓存使用笔记

    >笔记1:如果需要调用远程的Redis,那么您需要2步 步骤1: 在项目的web.config文件中配置 <!-- Cache.Redis连接配置 --> <add key=& ...

  8. 笔记:CS231n+assignment2(作业二)(三)

    终于来到了最终的大BOSS,卷积神经网络~ 这里我想还是主要关注代码的实现,具体的CNN的知识点想以后在好好写一写,CNN的代码关键就是要加上卷积层和池话层. 一.卷积层 卷积层的前向传播还是比较容易 ...

  9. spring in action 学习笔记九:如何证明在scope为prototype时每次创建的对象不同。

    spring 中scope的值有四个:分别是:singleton.prototype.session.request.其中session和request是在web应用中的. 下面证明当scope为pr ...

  10. bzoj [Sdoi2014]数数 AC自动机上dp

    [Sdoi2014]数数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1264  Solved: 636[Submit][Status][Discu ...