Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,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题,枚举剪枝)的更多相关文章
- Codeforces Gym 101194C Mr. Panda and Strips(2016 EC-Final,区间DP预处理 + 枚举剪枝)
题目链接 2016 EC-Final 题意 现在要找到数列中连续两个子序列(没有公共部分).要求这两个子序列本身内部没有重复出现的数. 求这两个子序列的长度的和的最大值. 首先预处理一下.令$ ...
- Gym 101194F Mr. Panda and Fantastic Beasts
#include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...
- 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 ...
- 【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和¬ ...
- hdu6007 Mr. Panda and Crystal 最短路+完全背包
/** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...
- HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)
HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others) Memory Limit: ...
- 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 ...
- 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 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
随机推荐
- Jenkins拾遗--第四篇-适当的让构建失败
问题的引出: 有一段我们的前端构建总会现git上分支名称中的版本号和工程里的版本号不一致的问题:这样会导致构一个问题:构建后的产品名称叫做1.1,但是进入app的关于页面,看到的版本还是1.0.这会让 ...
- 《Cracking the Coding Interview》——第4章:树和图——题目1
2014-03-19 03:30 题目:判断一个二叉树是否为平衡二叉树,即左右子树高度相差不超过1. 解法:递归算高度并判断即可. 代码: // 4.1 Implement an algorithm ...
- Bit与Byte的区别
在工作中遇到一些概念模糊的地方, 需要记住了bit意为“位”或“比特”,是计算机运算的基础: byte意为“字节”,是计算机文件大小的基本计算单位: 说到usb2.0标准接口传输速率.许多人都将“48 ...
- PyCharm 解决有些库(函数)没有代码提示
问题描述: 如图,当输入 im. 没有智能提示第三库相应的函数或其他提示. 解决方案: python是动态强类型语言,IDE无法判断Image.open("panda.png")的 ...
- appium-在页面点击一下处理(一般处理提示蒙层)
在写用例的时候,经常会发现某些第一次进去的页面会有一个蒙层提示.我们只有处理掉这个蒙层,才能继续我们的用例: 这边我们使用的是TouchAction的tap方法 TouchAction action ...
- 性能测试之siege
一.siege介绍 Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数 ...
- 每个套接字地址error
套接字问题 1 netstat -aon|findstr 5037 2 根据pid,查询占用端口的应用,这里的pid为 8672,查询命令如图 3 杀死对应的PID,taskkill /pid 8 ...
- postman导出excel出现response
https://jingyan.baidu.com/article/915fc414559b4351394b2084.html
- Python全栈工程师(递归函数、闭包)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 全栈工程师 Python人工智能从入门到精通 函数式编程: 是指用一系列函数解决问题 每一个函数完成细 ...
- class内部处理
class A { public: int foo( ) { return val ; } static int staFun( ) { return staVal ; } static int st ...