zoukankan      html  css  js  c++  java
  • 【bzoj3834】[Poi2014]Solar Panels 数论

    题目描述

    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


    题解

    数论

    结论:区间$(l,r]$中出现$n$的倍数的充要条件是$lfloorfrac rn floor>lfloorfrac ln floor$。

    于是可以枚举$i$,看是否在两段区间内都出现过。可以通过枚举商将时间复杂度将至$O(nsqrt a)$。

    注意在枚举商的时候要使用最后一个商与$b/i$和$d/i$相等的$last$值计算。

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main()
    {
    	int T , a , b , c , d , i , last , ans;
    	scanf("%d" , &T);
    	while(T -- )
    	{
    		scanf("%d%d%d%d" , &a , &b , &c , &d);
    		for(i = 1 ; i <= b && i <= d ; i = last + 1)
    		{
    			last = min(b / (b / i) , d / (d / i));
    			if(b / last > (a - 1) / last && d / last > (c - 1) / last) ans = last;
    		}
    		printf("%d
    " , ans);
    	}
    	return 0;
    }
    

     

  • 相关阅读:
    为什么CAP不能同时满足?
    多线程模式下高并发的环境中唯一确保单例模式---DLC双端锁
    有道词典命令行查询工具(Mac/Ubuntu)
    CentOS 6.9配置EPEL源
    GitHub官方Markdown语法教程
    CentOS 6.9设置阿里云源/163源
    Ubuntu 16.04安装Wine版的微信(deepin-wechat)
    普通主板设置BIOS实现电脑插电自动启动
    IntelliJ IDEA导出设置
    Linux下swap分区多大才合适的问题探讨
  • 原文地址:https://www.cnblogs.com/GXZlegend/p/7434565.html
Copyright © 2011-2022 走看看