bzoj3834 [Poi2014]Solar Panels 分块

16 篇文章 0 订阅

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

Solution


考虑枚举答案,答案合法当且仅当 a1ans<bans ⌊ a − 1 a n s ⌋ < ⌊ b a n s ⌋ c1ans<dans ⌊ c − 1 a n s ⌋ < ⌊ d a n s ⌋
这里原本想的是 aans+西bans ⌊ a a n s ⌋ + 奇 怪 东 西 ≤ ⌊ b a n s ⌋ 这样子的,结果有特殊情况会不好处理
看到整除下取整就上分块啊

洛谷上有一个点过不了是怎么回事,希望能有人教QAQ

Code


#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define drp(i,st,ed) for (int i=st;i>=ed;--i)
#define min(x,y) ((x)<(y)?(x):(y))

int read() {
    int x=0,v=1; char ch=getchar();
    for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):(v),ch=getchar());
    for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
    return x*v;
}

inline void writeln(int x){
    char ch[21]={}; int i=0;
    if (x<0) putchar('-');
    do {ch[++i]='0'+x%10;} while (x/=10);
    for (;i;) putchar(ch[i--]);
    putchar('\n');
}

int main(void) {
    for (int T=read();T--;) {
        int a=read()-1,b=read(),c=read()-1,d=read();
        if (b>d) std:: swap(a,c),std:: swap(b,d);
        int ans=0,l1,l2,r1,r2;
        for (int i=1,last;i<=b;i=last+1) {
            last=min(b/(b/i),d/(d/i));
            if (i<=a) last=min(last,a/(a/i));
            if (i<=c) last=min(last,c/(c/i));
            l1=a/i,r1=b/i;
            l2=c/i,r2=d/i;
            if (l1>=r1||l2>=r2) continue;
            ans=last;
        }
        writeln(ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值