社区讨论

和楼下有相同的个问题,为什么优先队列会RE

P1309[NOIP 2011 普及组] 瑞士轮参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@m42hdh84
此快照首次捕获于
2024/11/29 16:27
去年
此快照最后确认于
2024/11/29 16:44
去年
查看原帖
rt.
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long read(){
	long long 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<<1)+(x<<3)+(ch^48);
		ch=getchar();
	} 
	return x*f;
}
void write(long long x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	putchar(x%10+'0');
}
int s[100005],w[100005];
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>> q;
vector<tuple<int,int,int>> b;
signed main(){
	int n=read(),r=read(),Q=read();
	for(int i=1;i<=2*n;i++){
		s[i]=read();
	}
	for(int i=1;i<=2*n;i++){
		w[i]=read();
	}
	for(int i=1;i<=2*n;i++){
		q.push(make_tuple(s[i],2*n-i+1,w[i]));
	}
	for(int i=1;i<=r;i++){
		for(int j=1;j<=n;j++){
			auto u=q.top();
			q.pop();
			auto v=q.top();
			q.pop();
			if(get<2>(u)>get<2>(v)){
				int aa=get<0>(u)+1,bb=get<1>(u),cc=get<2>(u);
				b.push_back(make_tuple(aa,bb,cc));
				b.push_back(v);
			}
			else{
				int aa=get<0>(v)+1,bb=get<1>(v),cc=get<2>(v);
				b.push_back(make_tuple(aa,bb,cc));
				b.push_back(u);
			}			
		}
		for(auto v:b){
			q.push(v);
		}
		b.clear();
	}
	for(int i=1;i<Q;i++){
		q.pop();
	}
	auto c=q.top();
	write(2*n-get<1>(c)+1);
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...