zoukankan      html  css  js  c++  java
  • APIO2019

    device:

    用最小公倍数的知识或是画网格模拟转移,神仙们也可以找规律。然后就变成区间覆盖了。

    忘记特殊情况了,大众分→Ag

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef long long i64;
    const int N=2e6+6;
    const i64 INF=1e18+7;
    
    struct sgm{
        i64 x,y;
        bool operator<(const sgm a)const{
            return x<a.x||x==a.x&&y<a.y;
        }
    }t[N];
    int cnt;
    
    i64 gcd(i64 n,i64 m){
        while(n%m){
            swap(n,m);
            m%=n;
        }
        return m;
    }
    
    int main()
    {
        int n,i;
        i64 a,b,x,y;
        scanf("%d%lld%lld",&n,&a,&b);
        i64 l;
        if(a/gcd(a,b+1)>=(double)INF/b)
            l=INF;
        else
            l=a/gcd(a,b+1)*b;
        for(i=1;i<=n;i++){
            scanf("%lld%lld",&x,&y);
            if(y-x+1>=l){  //我怎么就这么睿智(
                printf("%lld",l);
                return 0;
            }
            else{
                x%=l,
                y%=l;
                if(x<=y){
                    ++cnt,
                    t[cnt].x=x,
                    t[cnt].y=y;
                }
                else{
                    ++cnt,
                    t[cnt].x=0,
                    t[cnt].y=y;
                    ++cnt,
                    t[cnt].x=x,
                    t[cnt].y=l-1;
                }
            }
        }
        sort(t+1,t+cnt+1);
        x=t[1].x,
        y=t[1].y;
        i64 s=0;
        for(i=2;i<=cnt;i++)
            if(t[i].x>y){
                s+=y-x+1;
                x=t[i].x,
                y=t[i].y;
            }
            else
                y=max(y,t[i].y);
        s+=y-x+1;
        printf("%lld",s);
        return 0;
    }

    bridges:

    分块

    lamps:

    不会做咕咕咕

  • 相关阅读:
    keepalive高可用
    springboot中bean的重定义
    jni有关知识点总结
    java并发问题总结
    openoffice将word转pdf中文乱码或消失的坑
    Redis实现分布式锁(Set和Lua)
    Redis java使用
    Redis 分区
    Redis 管道技术
    Redis 连接
  • 原文地址:https://www.cnblogs.com/wanghaoyu/p/APIO2019.html
Copyright © 2011-2022 走看看