zoukankan      html  css  js  c++  java
  • 【2017"百度之星"程序设计大赛

    【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6119


    【题意】


    在这里写题意

    【题解】


    先把相交的部分合成一个区间.
    这个可以用排序,加个简单的处理就能弄出来.
    然后,对于每个区间,枚举它最右能到达哪个区间,(用那m个补签卡);
    这个最右区间不需要每次重新算,它肯定是单调不递减的.
    注意如果那个最右的区间在枚举的区间i的左边的话,把最右区间置为枚举的区间。
    然后剩余的补签卡也用掉就好了。

    【错的次数】


    0

    【反思】


    在这了写反思

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define ri(x) scanf("%d",&x)
    #define rl(x) scanf("%lld",&x)
    #define rs(x) scanf("%s",x)
    #define oi(x) printf("%d",x)
    #define ol(x) printf("%lld",x)
    #define oc putchar(' ')
    #define os(x) printf(x)
    #define all(x) x.begin(),x.end()
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e5;
    
    
    pii a[N+10],b[N+10];
    int n,m,tot;
    
    
    int main(){
        //Open();
        //Close();
        while (~ri(n)){
            ri(m);
            rep1(i,1,n)
                ri(a[i].fi),ri(a[i].se);
            sort(a+1,a+1+n);
            tot = 0;
            rep1(i,1,n){
                tot++;
                b[tot].fi = a[i].fi;
                int j = i,r = a[i].se;
                while (j+1 <= n && a[j+1].fi-1 <= r){
                    r = max(r,a[j+1].se);
                    j++;
                }
                i = j;
                b[tot].se = r;
            }
    
    
            n = tot;
            int j = 1,ret = 0,ans = 0;
            rep1(i,1,n){
                if (j < i) j = i;
                while (j + 1 <= n && ret + b[j+1].fi-b[j].se-1 <= m){
                    ret+=b[j+1].fi-b[j].se-1;
                    j++;
                }
                if (i <=j && ret <= m) ans = max(ans,b[j].se-b[i].fi+1+m-ret);
                if (i < j)
                    ret-=b[i+1].fi-b[i].se-1;
            }
            oi(ans);puts("");
        }
        return 0;
    }
    


  • 相关阅读:
    jwt
    mybatis的回顾
    swagger
    MySQl总结
    Java异常
    常用Dos命令
    C++初级项目——机房预约系统
    C++中将数字型字符串转变为int类型的方法
    C++中int *a; int &a; int & *a; int * &a
    #define_CRT_SECURE_NO_WARNINGS的用法
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626091.html
Copyright © 2011-2022 走看看