【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. 手游LTV(用户终生价值)计算公式

    在承接APP推广项目中,手游价值变现最直接,核心是获取更多的充值,其中LTV(Lifetime-Value生命周期价值)是一个重要参考指标,可以理解为玩家在其生命周期内对游戏的平均贡献值,为什么要计算 ...

  2. Codeforces 922F Divisibility (构造 + 数论)

    题目链接  Divisibility 题意 给定$n$和$k$,构造一个集合$\left\{1, 2, 3, ..., n \right\}$的子集,使得在这个集合中恰好有$k$对正整数$(x, y) ...

  3. luogu P3116 [USACO15JAN]会议时间Meeting Time

    题目描述 Bessie and her sister Elsie want to travel from the barn to their favorite field, such that the ...

  4. lock与monitor的区别

    1.Lock 只能对引用对象加锁 Lock锁定区间内可以对锁定值修改而不发生运行时错误,通常也会采用此种修改方式.这种方式又有点类同于使用Monitor.Wait取得资源,并对这个资源进行操作. 用法 ...

  5. 2017.2.13 开涛shiro教程-第十二章-与Spring集成(二)shiro权限注解

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(二)shiro权限注解 shiro注 ...

  6. 2017.04.20 Adams仿真介绍

    Adams 仿真 | 验证"隐性机器人模型"概念,提高视觉伺服精度 产品:Adams行业:科研优势: 1.Adams 仿真可精确预测机器人的位置和方位 2.仿真在理论工作验证中起着 ...

  7. wordpress账户防暴力破解攻击

    一.修改数据库表前缀 默认的表前缀是wp_,如果你安装博客的时候没有修改,可以参考这篇文章修改下表前缀. 修改完登录测试下,如果登录成功后提示“您没有足够的权限访问该页面”,说明前缀没有修改完整,参照 ...

  8. 【设计模式】工厂方法(FactoryMethod)模式

    看不见PPT的请自行解决DNS污染问题. 相关类的代码: namespace FactoryPatternConsole.Model { public class Address { public s ...

  9. 手把手教你画AndroidK线分时图及指标

    先废话一下:来到公司之前.项目是由外包公司做的,面试初,没有接触过分时图k线这块,认为好难,我能搞定不.可是一段时间之后,发现之前做的那是一片稀烂,可是这货是主功能啊.迟早的自己操刀,痛下决心,开搞, ...

  10. ZOJ - 3890 Wumpus(BFS基础题)

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...