zoukankan      html  css  js  c++  java
  • 能量收集

    能量收集

    贪心题

    就两种操作,收集能量/ 回血 (防护也是回血)

    能收集能量就先疯狂收集,最后如果耐久不够了,找之前的耗损耐久最大的一天补回来。(大根堆维护)

    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    typedef long long ll;
    const int N=1e5+10;
    inline int 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 f*x;
    }
    void write(int x) {
    	static short st[32];short tp=0;
    	do st[++tp]=x%10,x/=10;while(x);
    	while(tp) putchar('0'|st[tp--]);
    	putchar('
    ');
    }
    int n,x,y,tol,energy;
    int mx=0,d[N];
    priority_queue<int>q; 
    int main() {
    	n=read();x=read();y=read();tol=read();energy=read();
    	for(int i=1;i<=n;i++) d[i]=read();//damage
    	int now=0;
    	for(int i=1;i<=n;i++) {
    		q.push(max(y,d[i]));
    		now+=x;
    		mx=max(mx,now);
    		if(now>=energy) {
    			puts("YES");
    			write(i);
    			return 0;
    		} 
    		tol-=d[i];
    		while(tol<=0&&q.size()) now-=x,tol+=q.top(),q.pop();
    	}
    	puts("NO");
    	write(mx);
    	return 0;
    }
    
    
  • 相关阅读:
    vue CDN seting
    AutoMapper
    c# list<class> to datatable
    vue watch
    net core 3.1 open file
    net core 3.1 area Global
    net core 3.1 area
    ef core log
    3.1 ef core
    3.1 daper
  • 原文地址:https://www.cnblogs.com/ke-xin/p/13950908.html
Copyright © 2011-2022 走看看