BZOJ 3834 [Poi2014]Solar Panels 数学

题意:

n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值。

解析:

md以前有个结论忘了结果这题坑我30分钟+

我们显然可以找到一个结论。

令gcd(x,y)=z;

那么显然有(smin-1)/z

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        int ans=-1;
        int la;
        for(int i=1;i<=y1&&i<=y2;i=la+1)
        {
            la=min(y1/(y1/i),y2/(y2/i));
            if(y1/la>(x1-1)/la&&y2/la>(x2-1)/la)
                ans=max(ans,la);
        }
        printf("%d\n",ans);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-12 03:10:31

BZOJ 3834 [Poi2014]Solar Panels 数学的相关文章

BZOJ 3834 Poi2014 Solar Panels 数论

题目大意:给定a,b,c,d,多次询问a<=x<=b,c<=x<=d时Gcd(x,y)的最大值ぽい 考虑枚举n=Gcd(x,y),那么[a,b]和[c,d]两个区间内存在n的倍数当且仅当floor(b/n)>floor((a-1)/n)且floor(d/n)>floor((c-1)/n)ぽい 由于后面的式子最多有O(√max(b,d))个取值,因此枚举商就可以了ぽい 1L和2L写了啥ぽい- - #include <cstdio> #include <c

【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 w

BZOJ3834 [Poi2014]Solar Panels

我和数论没完了.. 这题就是要找 a ∈ [mn1, mx1], b ∈ [mn2, mx2] 的最大 gcd(a, b) 不妨设 mx1 < mx2,如果mn1 > mn2则答案就是mx1 否则我们要找到一个最大的x使得 a ∈ [mn1 / x, mx1 / x], b ∈ [mn2 / x, mx2 / x], 满足gcd(a, b) ≥ 1 分块搞搞,判断一下区间大小≥1就好了 1 /***************************************************

BZOJ 3524: [Poi2014]Couriers

3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][Status][Discuss] Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. Input 第一行两个数n,m.第二行n个数,a[i].接下来m行,

bzoj 3831: [Poi2014]Little Bird

3831: [Poi2014]Little Bird Description In the Byteotian Line Forest there are   trees in a row. On top of the first one, there is a little bird who would like to fly over to the top of the last tree. Being in fact very little, the bird might lack the

BZOJ 3524: [Poi2014]Couriers( 主席树 )

卡我空间.... 这道题应该是主席树入门题...无修改 , 离散化都不用...出题人业界良心啊 一开始的空白树我 build 出来结果就多了整整 2n 个 Node , 然后就 MLE 了... ( 双倍经验 , 另一道见上图 ) ---------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring&g

bzoj 3832: [Poi2014]Rally(线段树+拓扑排序)

3832: [Poi2014]Rally Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special Judge Submit: 113  Solved: 56 [Submit][Status][Discuss] Description An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclis

BZOJ 2751 [HAOI2012]容易题 数学

题意:链接 方法:数学+瞎搞(注意取模问题) 解析:这题其实也没啥好说的,随便写写就出来了,我就直接挂几个过程.a[i].n表示第i位第n种取值. a[1].1?a[2].1?...?a[n].1+ a[1].1?...?a[n].2+...+ a[1].1?...?a[n].x = a[1].1?a[2].1?...?∑xi=1a[n] 同理局部分析每一项 得到结果 ∑xi=1a[1]?∑xi=1a[2]?...?∑xi=1a[n] 所以只要处理每一项的和就可以了. 后记:考试的时候脑残加了个

【刷题】BZOJ 3832 [Poi2014]Rally

Description An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclists. Local representatives of motorcyclists, long feuding the cyclists, have decided to sabotage the event. There are intersections