BZOJ3834[Poi2014]Solar Panels——分块
题目描述
输入
输出
样例输入
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24
样例输出
7
2
5
提示
枚举区间内每个数求gcd显然不可做,我们不妨换一种思路,枚举gcd。
那么如何判断区间内是否有这个gcd?
只要(l-1)/gcd<r/gcd就能确定区间内有这个gcd了。
剩下的就是枚举gcd了,因为x/gcd只有√x种取值,所以直接整除分块,每次取块内最后一个就好了。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int n;
int A,B,C,D;
int main()
{
scanf("%d",&n);
while(n--)
{
int ans=0;
scanf("%d%d%d%d",&A,&B,&C,&D);
A--;
C--;
int r;
for(int l=1;l<=B&&l<=D;l=r+1)
{
r=min(B/(B/l),D/(D/l));
if(A/r<B/r&&C/r<D/r)
{
ans=r;
}
}
printf("%d\n",ans);
}
}
BZOJ3834[Poi2014]Solar Panels——分块的更多相关文章
- 【BZOJ3834】[Poi2014]Solar Panels 分块好题
[BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...
- BZOJ3834 [Poi2014]Solar Panels 【数论】
题目链接 BZOJ3834 题解 容易想到对于\(gcd(x,y) = D\),\(d\)的倍数一定存在于两个区间中 换言之 \[\lfloor \frac{a - 1}{D} \rfloor < ...
- BZOJ3834 : [Poi2014]Solar Panels
问题相当于找到一个最大的k满足在$[x_1,x_2]$,$[y_1,y_2]$中都有k的倍数 等价于$\frac{x_2}{k}>\frac{x_1-1}{k}$且$\frac{y_2}{k}& ...
- bzoj 3834 [Poi2014]Solar Panels 数论分块
3834: [Poi2014]Solar Panels Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 367 Solved: 285[Submit] ...
- 【bzoj3834】[Poi2014]Solar Panels 数论
题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...
- 【BZOJ】3834: [Poi2014]Solar Panels
http://www.lydsy.com/JudgeOnline/problem.php?id=3834 题意:求$max\{(i,j)\}, smin<=i<=smax, wmin< ...
- [POI2014]Solar Panels
题目大意: $T(T\le1000)$组询问,每次给出$A,B,C,D(A,B,C,D\le10^9)$,求满足$A\le x\le B,C\le y\le D$的最大的$\gcd(x,y)$. 思路 ...
- BZOJ3834:Solar Panels (分块)
题意 询问两个区间[smin,smax],[wmin,smax]中是否存在k的倍数,使得k最大 分析 将其转化成\([\frac{smin-1}k,\frac{smax}k],[\frac{wmin- ...
- Luogu3579 Solar Panels
整除分块枚举... 真的没有想到会这么简单. 要使一个数 \(p\) 满足 条件, 则 存在\(x, y\), \(a<=x \times p<=b\ \&\&\ c< ...
随机推荐
- [TPYBoard - Micropython之会python就能做硬件 开篇]会python就能做硬件!
转载请注明:@小五义http://www.cnblogs.com/xiaowuyiQQ群:64770604 会python就能做硬件! 在写这套教程之前,首先感觉山东萝卜电子科技有限公司(turnip ...
- C++11 并发指南四(<future> 详解一 std::promise 介绍)
前面两讲<C++11 并发指南二(std::thread 详解)>,<C++11 并发指南三(std::mutex 详解)>分别介绍了 std::thread 和 std::m ...
- 关于TCP和MQTT之间的转换
现在物联网流行的就是MQTT 其实MQTT就是在TCP的基础上建立了一套协议 可以看这个,本来我自己想用Wireshark监听一下,不过百度一搜索一大把,我就不测试了 https://blog.csd ...
- Matplotlib 简单图例
图例参考:http://matplotlib.org/gallery.html API参考:http://matplotlib.org/api/pyplot_summary.html # -*- co ...
- Python学习总结 05 pandas
pandas官方网址 : http://pandas.pydata.org/ . pandas的安装比较复杂,如果想开箱即用,可以考虑下载WinPython.WinPython的官方地址是: htt ...
- Luogu4199 万径人踪灭 FFT、Manacher
传送门 先不考虑”不是连续的一段“这一个约束条件.可以知道:第$i$位与第$j$位相同,可以对第$\frac{i+j}{2}$位置上产生$1$的贡献(如果$i+j$为奇数表明它会对一条缝产生$1$的贡 ...
- 轻量级WebApi请求插件:PostMan
时间很宝贵,废话不多说,只说三句,如下: 十年河东,十年河西,莫欺骚年穷!~_~ 打错个字,应该是莫欺少年穷! 学历代表你的过去,能力代表你的现在,学习代表你的将来. 学无止境,精益求精. 本次介绍的 ...
- C. Multiplicity
链接 [http://codeforces.com/contest/1061/problem/C] 题意 给你一个数组,让你找有多少个子串(并非连续,但相对位置不能换),满足bi%i==0; 分析 d ...
- Let the Balloon Rise HDU水题
题意 让你统计字符串最多的那个串,并输出 分析 直接用map统计,不断更新最大值即可 代码 #include<iostream> #include<algorithm> #in ...
- Linux: HowTo See Directory Tree Structure
https://www.cyberciti.biz/faq/linux-show-directory-structure-command-line/ Linux: HowTo See Director ...