zoukankan      html  css  js  c++  java
  • 5.6水题记录

    BZOJ 1029

    确实是水题,由于人弱想了半天.

    这题我以前好像做到过T^T...

    原来贪心就可以了.据gty说,贪心策略:

    能加则加

    不能加尽量省出时间来.

    感觉好奇葩,不知道为什么是对的...感觉正确性并不显然...先这么写了.

    #include <cstdio>
    #include <ext/pb_ds/priority_queue.hpp>
    #include <algorithm>
    __gnu_pbds::priority_queue<int,std::less<int>> q;
    int n,m,i,j,k;
    inline int read(){//hzwer read
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    struct Q{
    	int e,t;
    } s[200000];
    bool c(const Q& a,const Q& b){
    	return a.e<b.e;
    }
    int main(){
    	n=read();
    	for(i=0;i<n;++i) s[i].t=read(),s[i].e=read();
    	std::sort(s,s+n,c);
    	for(i=0;i<n;++i){
    		if(j+s[i].t<=s[i].e){
    			++k;
    			j+=s[i].t;
    			q.push(s[i].t);
    		}else{
    			m=q.top();
    			if(m>s[i].t){
    				q.pop();
    				q.push(s[i].t);
    				j=j-m+s[i].t;
    			}
    		}
    	}
    	printf("%d
    ",k);
    	return 0;
    }
    

    STL玩玩就水过了.

  • 相关阅读:
    PHP之目录遍历
    PHP之验证码
    PHP之验证码
    PHP之异常处理模式
    PHP之pdo的预处理模式
    PHP之PDO
    PHP之cookie和session
    PHP之MVC
    单例模式
    ThreadLocal
  • 原文地址:https://www.cnblogs.com/tmzbot/p/4485055.html
Copyright © 2011-2022 走看看