zoukankan      html  css  js  c++  java
  • poj3171 Cleaning Shifts

    传送门

    题目大意

    有一个大区间和n个小区间,每个小区间都有一个代价,求最少付出多少代价可以使得小区间完全覆盖大区间。

    分析
    为了方便起见我们先将s变为2,其它的位置都对应更改以便后期处理。我们考虑以t1为第一关键字,t2为第二关键字将所有奶牛排序。用dp[i][j]表示考虑到第i只牛,覆盖到点j最少需要多少钱。我们可以将i这一维去掉,则dp[j]=min{dp[j],dp[j'](t1-1<=j'<=t2-1)}。然后进行线段树优化就可以了。

    代码

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<queue>
    #include<ctime>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    using namespace std;
    const long long inf = 1e12+7;
    struct node {
        long long t1,t2,sum;
    };
    node wh[11000];
    long long d[880000];
    inline bool cmp(const node x,const node y){
           if(x.t1==y.t1)return x.t2<y.t2;
           return x.t1<y.t1;
    }
    inline void build(long long le,long long ri,long long wh,long long pl,long long k){
          if(le==ri){
              d[wh]=k;
              return;
          }
          long long mid=(le+ri)>>1;
          if(mid>=pl)build(le,mid,wh<<1,pl,k);
            else build(mid+1,ri,wh<<1|1,pl,k);
          d[wh]=min(d[wh<<1],d[wh<<1|1]);
          return;
    }
    inline long long q(long long le,long long ri,long long wh,long long x,long long y){
          if(le>=x&&ri<=y){
              return d[wh];
          }
          long long mid=(le+ri)>>1,ans=inf;
          if(mid>=x)ans=min(ans,q(le,mid,wh<<1,x,y));
          if(mid<y)ans=min(ans,q(mid+1,ri,wh<<1|1,x,y));
          return ans;
    } 
    int main(){
          long long n,s,t,i,j,k;
          scanf("%lld%lld%lld",&n,&s,&t);
          for(i=1;i<=n;i++){
              scanf("%lld%lld%lld",&wh[i].t1,&wh[i].t2,&wh[i].sum);
              wh[i].t1+=2;
              wh[i].t2+=2;
              wh[i].t1-=s;
              wh[i].t2-=s;
          }
          t=(t-s)+2,s=2;
          build(1,t,1,1,0);
          for(i=s;i<=t;i++)
            build(1,t,1,i,inf);
          sort(wh+1,wh+n+1,cmp);
          for(i=1;i<=n;i++){
              long long x=min(q(1,t,1,wh[i].t2,wh[i].t2),
                      q(1,t,1,wh[i].t1-1,wh[i].t2-1)+wh[i].sum);
              build(1,t,1,wh[i].t2,x);
          }
          long long x=q(1,t,1,t,t);
          if(x>=inf)x=-1;
          printf("%lld
    ",x);
          return 0;
    }
  • 相关阅读:
    Powershell数据处理
    Powershell About Active Directory Group Membership of a domain user
    Powershell About Active Directory Server
    Oracle Schema Objects——Tables——TableStorage
    Oracle Schema Objects——Tables——TableType
    English Grammar
    Oracle Database Documentation
    Oracle Schema Objects——Tables——Oracle Data Types
    Oracle Schema Objects——Tables——Overview of Tables
    What is Grammar?
  • 原文地址:https://www.cnblogs.com/yzxverygood/p/9476145.html
Copyright © 2011-2022 走看看