RE求助!!!
查看原帖
RE求助!!!
421758
HANDSOME_FZZ楼主2023/7/17 09:58
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#define N 1000005
using namespace std;
int w[N],n,k,T,ans;
struct snack1{
	int j,id;
	friend bool operator<(snack1 a,snack1 b) 
    {
        return a.j<b.j||(a.j==b.j && a.id<b.id);//大的在前
    }//重载运算符
}s;
priority_queue <snack1> q;

struct snack2{
	int j,id;
	friend bool operator<(snack2 a,snack2 b) 
    {
        return a.j>b.j||(a.j==b.j && a.id>b.id);//升序
    }
}b,sb;
priority_queue <snack2> z;

int read(){
	int x=0,f=1; char c;
	c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}

void in(int p,int c){
	snack1 f1; snack2 f2;
	f1.j=f2.j=p; f1.id=f2.id=c;
	q.push(f1); z.push(f2);
}

void get(){
	z.pop(); s.j-=b.j;
	in(s.j,s.id);
	s=q.top(),b=z.top(); z.pop(); sb=z.top();
}

bool ok(int kg,int cnt){
	//cout<<s.j<<' '<<b.j<<' '<<sb.j<<' '<<ans<<endl;
	if(ans<=1) return 0;
	if(ans==2) return 1;//两条蛇一定吃 
	if(cnt==2){
		if(kg%2) ans--;
		return 0;
	}
	if(s.j-b.j>=sb.j||(s.j-b.j==sb.j && s.id>sb.id)){
		if(kg==1) return 1;//吃完不是最弱的 吃了继续模拟 
		else{
			if(kg%2) ans--; //奇数层
			return 0;  
		}
	}
	get();//假设把它吃掉 
	return ok(kg+1,cnt-1);
}

void battle(){
	ans=n;
	s=q.top(),b=z.top();
	z.pop(); sb=z.top();
	//cout<<s.j<<' '<<b.j<<' '<<sb.j<<endl;
	while(ok(1,ans)){
		ans--;
		get();
	}
	cout<<ans<<endl;
}

void loading(){
	T=read(); n=read(); 
	for(int i=1;i<=n;i++){ w[i]=read(); in(w[i],i); }
	//cout<<q.top().j<<' '<<z.top().j<<endl;
	battle();
	for(int i=1;i<T;i++){
		while(q.size()) q.pop();//优先队列没有clear() 
		while(z.size()) z.pop();
		k=read(); int a,c;
		for(int j=1;j<=k;j++){
			a=read(); c=read();
			w[a]=c;
		}
		for(int j=1;j<=n;j++) in(w[j],j); 
		battle();
	}/**/
}

int main(){
	//freopen("P7078.in","r",stdin);
	//freopen("snacks.out","w",stdout);
	loading();
	return 0;
}
2023/7/17 09:58
加载中...