zoukankan      html  css  js  c++  java
  • BZOJ1293: [SCOI2009]生日礼物

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1293

    记录下每个点的颜色和上一个这一个颜色点的坐标,离散化之后枚举终点向前扫一遍。。

    #include<cstring>
    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cmath>
    #include<algorithm>
    #define rep(i,l,r) for (int i=l;i<=r;i++)
    #define down(i,l,r) for (int i=l;i>=r;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define low(x) (x&(-x)) 
    #define maxn 1005000
    #define inf int(1e9)
    #define mm 1000000007
    #define ll long long
    using namespace std;
    int pre[maxn],last[maxn],a[maxn],v[maxn],n,m,ans,cnt;
    ll read(){
        ll x=0,f=1; char ch=getchar();
        while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
        while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    bool cal(int x){
        int mx=0;
        rep(i,1,m){
            while (v[last[i]]>x) {
                if (pre[last[i]]==0) return 0;
                last[i]=pre[last[i]];
            }
            if (last[i]<=x) mx=max(mx,x-v[last[i]]);
        }
        ans=min(ans,mx);
        return 1;
    }
    int main(){
    //  freopen("in.txt","r",stdin);
        n=read(); m=read();
        rep(i,1,m){
            int t=read();
            rep(j,1,t){
                int x=read(); v[++cnt]=x; a[cnt]=x;
                pre[cnt]=last[i]; last[i]=cnt;
            }
        } 
        sort(a+1,a+1+cnt);
        ans=inf;
        down(i,cnt,1){
            if (a[i]!=a[i+1]) {
                if (!cal(a[i])) break;
            }
        }
        printf("%d
    ",ans);
        return 0;
    } 
  • 相关阅读:
    [ARC 102D]All Your Paths are Different Lengths
    [NOI 2016] 优秀的拆分
    [TJOI 2015] 线性代数
    [LUOGU 4717] 快速沃尔什变换
    [NOI 2006] 最大获利
    Javascript继承机制的设计
    必应输入法产品分析
    你不得不知道的HTML5的新型标签
    Mobile Web
    10行代码爬取网页
  • 原文地址:https://www.cnblogs.com/ctlchild/p/5131676.html
Copyright © 2011-2022 走看看