题目描述

Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appears that he has hit the gold as within a few days  clients walked through his door. Each client has ordered a single rectangular panel with specified width and height ranges.
The panels consist of square photovoltaic cells. The cells are available in all integer sizes, i.e., with the side length integer, but all cells in one panel have to be of the same size. The production process exhibits economies of scale in that the larger the cells that form it, the more efficient the panel. Thus, for each of the ordered panels, Byteasar would like to know the maximum side length of the cells it can be made of.
n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值。

输入

The first line of the standard input contains a single integer N(1<=N<=1000): the number of panels that were ordered. The following   lines describe each of those panels: the i-th line contains four integers Smin,Smax,Wmin,Wmax(1<=Smin<=Smax<=10^9,1<=Wmin<=Wmax<=10^9), separated by single spaces; these specify the minimum width, the maximum width, the minimum height, and the maximum height of the i-th panel respectively.

输出

Your program should print exactly n lines to the standard output. The i-th line is to give the maximum side length of the cells that the i-th panel can be made of.

样例输入

4
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24

样例输出

8
7
2
5

提示

Explanation: Byteasar will produce four solar panels of the following sizes: 8*8 (a single cell), 7*14 (two cells), 4*22 or 6*22 (22 or 33 cells respectively), and 5*20 (four cells).

枚举区间内每个数求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——分块的更多相关文章

  1. 【BZOJ3834】[Poi2014]Solar Panels 分块好题

    [BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...

  2. BZOJ3834 [Poi2014]Solar Panels 【数论】

    题目链接 BZOJ3834 题解 容易想到对于\(gcd(x,y) = D\),\(d\)的倍数一定存在于两个区间中 换言之 \[\lfloor \frac{a - 1}{D} \rfloor < ...

  3. 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}& ...

  4. bzoj 3834 [Poi2014]Solar Panels 数论分块

    3834: [Poi2014]Solar Panels Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 367  Solved: 285[Submit] ...

  5. 【bzoj3834】[Poi2014]Solar Panels 数论

    题目描述 Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appea ...

  6. 【BZOJ】3834: [Poi2014]Solar Panels

    http://www.lydsy.com/JudgeOnline/problem.php?id=3834 题意:求$max\{(i,j)\}, smin<=i<=smax, wmin< ...

  7. [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)$. 思路 ...

  8. BZOJ3834:Solar Panels (分块)

    题意 询问两个区间[smin,smax],[wmin,smax]中是否存在k的倍数,使得k最大 分析 将其转化成\([\frac{smin-1}k,\frac{smax}k],[\frac{wmin- ...

  9. Luogu3579 Solar Panels

    整除分块枚举... 真的没有想到会这么简单. 要使一个数 \(p\) 满足 条件, 则 存在\(x, y\), \(a<=x \times p<=b\ \&\&\ c< ...

随机推荐

  1. liunx基础知识

    学习Linux系统的重要性应该不用多说,下面我就对Linux的基础知识进行一个全面而又简单的总结.不过建议大家还是装个Linux系统多练习,平时最好只在Linux环境下编程,这样会大有提高. linu ...

  2. ubuntu (14.04) 卸载 gnome 系统桌面

    1.将ubuntu 的图形界面切到命令行界面. 2.卸掉 gnome-shell 的主程序 sudo apt-get remove gnome-shell 3.卸载 gnome sudo apt-ge ...

  3. MIPI接口资料汇总(精)

    一.介绍 1.MIPI联盟,即移动产业处理器接口(Mobile Industry Processor Interface 简称MIPI)联盟.MIPI(移动产业处理器接口)是MIPI联盟发起的为移动应 ...

  4. IIR数字滤波器的实现(C语言)

    经典滤波器和数字滤波器 一般滤波器可以分为经典滤波器和数字滤波器. 经典滤波器:假定输入信号中的有用成分和希望去除的成分各自占有不同的频带.如果信号和噪声的频谱相互重迭,经典滤波器无能为力.比如 FI ...

  5. 转 edtools

     1.下载工具包:edtools.rar ,解压后放到磁盘的何意一个目录,如D:\edTools. 2.打开ED,打开“工具”-“配置用户工具”,在弹出的对象框中,在“组和工具项目”下拉框中选择一个工 ...

  6. python第二周。2019.4.13

    1, 我绘制大蟒蛇就是..保存也对着呢,你要是打开文件的话,先闪个黑屏,再闪个白屏..自动退出,然后啥都没了. 我觉得是我代码编错了...再来一遍! 这次到可以,但是这个大蟒蛇好像没有回头... 刚才 ...

  7. 分布式监控系统Zabbix-图形集中展示插件Graphtree安装笔记

    Zabbix想要集中展示图像,唯一的选择是screen,后来zatree解决了screen的问题,但性能不够好.Graphtree 由OneOaaS开发并开源出来,用来解决Zabbix的图形展示问题, ...

  8. 5 questions

    1.软件开发中有哪几种过程模型? 2.详细设计有哪几种描述方法? 3.什么是需求分析? 4.软件设计的基本原理包括哪些内容? 5.简述文档在软件工程中的作用? 逸翔.

  9. leetcode: 638.大礼包

    题目描述: https://leetcode-cn.com/problems/shopping-offers/ 解题思路: 这类求最大最小的问题首先想到的就是用DP求解. 这题还用到了递归,首先计算单 ...

  10. 第三个Sprint冲刺第4天

    成员:罗凯旋.罗林杰.吴伟锋.黎文衷 讨论内容:各成员汇报各自完成的情况.