zoukankan      html  css  js  c++  java
  • 【BZOJ3834】[Poi2014]Solar Panels 分块好题

    【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-1over x} floor < lfloor{Bover x} floor && lfloor {C-1over x} floor < lfloor {Dover x} floor$。

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

    #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
    ",ans);
    	}
    	return 0;
    }
  • 相关阅读:
    UART中的硬件流控RTS与CTS
    Yii smsto短信接口的函数
    分布式选主 利用Mysql ACID和Lease协议实现选主和高可用
    Extjs GridPanel 合计功能 解决滚动条滚动问题和页面刷新滚动条回到初始位置问题。
    基于ARM+LINUX的无线视频采集系统设计搭建嵌入式web服务器
    C++里父类的析构函数为什么声明为virtual
    重量过载 = 重载
    Spread Studio中文支持图解
    Android用户如何FQ访问被封锁的媒体资源
    将myeclipse 10.x以下版本web project的导入到myeclipse blue 2013 部署没有项目名
  • 原文地址:https://www.cnblogs.com/CQzhangyu/p/7434647.html
Copyright © 2011-2022 走看看