zoukankan      html  css  js  c++  java
  • bzoj 1029: [JSOI2007]建筑抢修

    Description

      小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的
    入侵者。但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建筑设施将会完全
    毁坏。现在的情况是:T部落基地里只有一个修理工人,虽然他能瞬间到达任何一个建筑,但是修复每个建筑都需
    要一定的时间。同时,修理工人修理完一个建筑才能修理下一个建筑,不能同时修理多个建筑。如果某个建筑在一
    段时间之内没有完全修理完毕,这个建筑就报废了。你的任务是帮小刚合理的制订一个修理顺序,以抢修尽可能多
    的建筑。

    Input

      第一行是一个整数N接下来N行每行两个整数T1,T2描述一个建筑:修理这个建筑需要T1秒,如果在T2秒之内还
    没有修理完成,这个建筑就报废了。

    Output

      输出一个整数S,表示最多可以抢修S个建筑.N < 150,000;  T1 < T2 < maxlongint

    Sample Input

    4
    100 200
    200 1300
    1000 1250
    2000 3200

    Sample Output

    3

    HINT

    Source

    按这种思维搞下去,迟早AFO了,碰到贪心题就挂烂了

    太羞耻了,大致就是就是用堆来调整排序后的贪心,因为后面修的堆前面没影响,然后就是要让对后面的影响尽量小;

    // MADE BY QT666
    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const int N=300050;
    int gi(){
      int x=0,flag=1;
      char ch=getchar();
      while(ch<'0'||ch>'9'){if(ch=='-') flag=-1;ch=getchar();}
      while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
      return x*flag;
    }
    struct data{
      int t1,t2;
    }house[N];
    bool cmp(const data &a,const data &b){
      if(a.t2==b.t2) return a.t1<b.t1;
      else return a.t2<b.t2;
    }
    priority_queue<int>q;
    int main(){
      int n=gi();
      for(int i=1;i<=n;i++){
        house[i].t1=gi(),house[i].t2=gi();
      }
      sort(house+1,house+1+n,cmp);
      q.push(house[1].t1);int ans=1,time=house[1].t1;
      for(int i=2;i<=n;i++){
        if(time+house[i].t1<=house[i].t2){
          ans++;time+=house[i].t1;
          q.push(house[i].t1);
        }
        else{
          int Max=q.top();
          if(house[i].t1<Max){
    	time=time-Max+house[i].t1;
    	q.pop();q.push(house[i].t1);
          }
        }
      }
      printf("%d
    ",ans);
      return 0;
    }
    
  • 相关阅读:
    词云
    结巴分词
    重复值处理
    异常值判断
    MySQL基本使用
    缺失值处理
    fit_transform和transform的区别
    sklearn学习笔记之简单线性回归
    图解机器学习
    Unity---UNet学习(1)----基本方法介绍
  • 原文地址:https://www.cnblogs.com/qt666/p/6957060.html
Copyright © 2011-2022 走看看