【BZOJ3834】[Poi2014]Solar Panels

Description

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)的最大值。

Input

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.

Output

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.

Sample Input

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

Sample Output

8
7
2
5

HINT

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).

题解:首先枚举答案x,x合法当且仅当$\lfloor{A-1\over x}\rfloor < \lfloor{B\over x} \rfloor \&\& \lfloor {C-1\over x}\rfloor < \lfloor {D\over x}\rfloor$。

然后分块,找最大值即可。

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,A,B,C,D,ans,i,last;
int main()
{
scanf("%d",&n);
while(n--)
{
ans=0;
scanf("%d%d%d%d",&A,&B,&C,&D),A--,C--;
for(i=1;i<=B&&i<=D;i=last+1)
{
last=min(B/(B/i),D/(D/i));
if(A/last<B/last&&C/last<D/last) ans=last;
}
printf("%d\n",ans);
}
return 0;
}

【BZOJ3834】[Poi2014]Solar Panels 分块好题的更多相关文章

  1. BZOJ3834[Poi2014]Solar Panels——分块

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

  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. BZOJ 2724 蒲公英 | 分块模板题

    题意 给出一个序列,在线询问区间众数.如果众数有多个,输出最小的那个. 题解 这是一道分块模板题. 一个询问的区间的众数,可能是中间"整块"区间的众数,也可能是左右两侧零散的数中的 ...

  9. Luogu 2801 教主的魔法 | 分块模板题

    Luogu 2801 教主的魔法 | 分块模板题 我犯的错误: 有一处l打成了1,还看不出来-- 缩小块大小De完bug后忘了把块大小改回去就提交--还以为自己一定能A了-- #include < ...

随机推荐

  1. 解决IE6的PNG透明

    http://www.jb51.net/article/35669.htm http://blog.csdn.net/mosliang/article/details/6760028

  2. (持续集成)win7上部署Jenkins+MSBuild+Svn+SonarQube+SonarQube Scanner for MSBuild (第二发)

    这一篇进入实战,走起.... 登录jenkins,如下图 点击上图中的“新建”按钮,进入下图 输入项目名称,选择“构建一个自由风格的软件项目”即可,点击“ok”,跳转到下图 svn源代码管理(选择代码 ...

  3. IntelliJ IDEA设置鼠标移动到方法上提示API注释

    参考: https://www.cnblogs.com/guazi/p/6474426.html(图片转自此篇文章)

  4. vim display line number

    cd /etc/vim sudo chmod 777 vimrc add :ser number to vimrc, then save and quit

  5. 80端口被屏蔽解决方法,80端口穿透之NAT端口映射技术

    介绍一种NAT端口映射技术应用,达到80端口穿透目的,解决80端口被屏蔽的问题,也是80端口被屏蔽解决方法中经常用到的. 80端口穿透类似80端口转发,因为80端口被屏蔽,在数据层面来说是不能直接访问 ...

  6. Django 创建APP - 简单路由系统案例

    架构图: setting.py: INSTALLED_APPS = [ ... 'bootstrap', ] myapp -> myapp -> urls.py from django.c ...

  7. ASP.NET MVC Web API 学习笔记---第一个Web API程序【转】

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html 1. Web API简单说明 近来很多大型的平台都公开了Web API. ...

  8. struts2.16中文乱码问题解决

    方法1.在struts.xml文件中添加<constant name="struts.i18n.encoding" value="GBK" /> 方 ...

  9. excel导出 jxl.jar包

    导入jxl.jar包, 代码如下: package com.gree; import java.io.IOException; import java.io.OutputStream; import ...

  10. rename命令

    rename命令用字符串替换的方式批量改变文件名. 语法 rename(参数) 参数 原字符串:将文件名需要替换的字符串: 目标字符串:将文件名中含有的原字符替换成目标字符串: 文件:指定要改变文件名 ...