• BZOJ 1293 生日礼物(尺取法)


    把坐标离散化之后就是很普通的尺取法啦。

    # include <cstdio>
    # include <cstring>
    # include <cstdlib>
    # include <iostream>
    # include <vector>
    # include <queue>
    # include <stack>
    # include <map>
    # include <set>
    # include <cmath>
    # include <algorithm>
    using namespace std;
    # define lowbit(x) ((x)&(-x))
    # define pi 3.1415926535
    # define eps 1e-9
    # define MOD 100000007
    # define INF 1000000000
    # define mem(a,b) memset(a,b,sizeof(a))
    # define FOR(i,a,n) for(int i=a; i<=n; ++i)
    # define FO(i,a,n) for(int i=a; i<n; ++i)
    # define bug puts("H");
    # define lch p<<1,l,mid
    # define rch p<<1|1,mid+1,r
    # define mp make_pair
    # define pb push_back
    typedef pair<int,int> PII;
    typedef vector<int> VI;
    # pragma comment(linker, "/STACK:1024000000,1024000000")
    typedef long long LL;
    int Scan() {
        int res=0, flag=0;
        char ch;
        if((ch=getchar())=='-') flag=1;
        else if(ch>='0'&&ch<='9') res=ch-'0';
        while((ch=getchar())>='0'&&ch<='9')  res=res*10+(ch-'0');
        return flag?-res:res;
    }
    void Out(int a) {
        if(a<0) {putchar('-'); a=-a;}
        if(a>=10) Out(a/10);
        putchar(a%10+'0');
    }
    const int N=1000005;
    //Code begin...
    
    struct Node{int c; LL pos;}node[N];
    int vis[65], num;
    
    bool comp(Node a, Node b){return a.pos<b.pos;}
    int main ()
    {
        LL ans=(LL)1<<60;
        int n, k, t;
        n=Scan(); k=Scan();
        FOR(i,1,k) {
            t=Scan();
            while (t--) node[++num].pos=Scan(), node[num].c=i;
        }
        sort(node+1,node+n+1,comp);
        num=0;
        int l=1, r=0;
        while (1) {
            while (num<k) {
                ++r;
                if (r>n) break;
                if (vis[node[r].c]==0) ++num;
                ++vis[node[r].c];
            }
            if (r>n) break;
            ans=min(ans,node[r].pos-node[l].pos);
            --vis[node[l].c];
            if (vis[node[l].c]==0) --num;
            ++l;
        }
        printf("%lld
    ",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    Codeforces 884E E. Binary Matrix
    基础练习 矩形面积交
    蓝桥杯基础练习---矩阵乘法
    C. An impassioned circulation of affection(Round 418)
    B. An express train to reveries(Round 418)
    A. An abandoned sentiment from past (Round 418)
    数学建模培训二 ---- matlab的基本应用
    数学建模培训第一天---线性规划
    基础练习 回形取数
    github初步---将本地代码传到github上面
  • 原文地址:https://www.cnblogs.com/lishiyao/p/6550055.html
Copyright © 2020-2023  润新知