跳到正文

题解

题解:P12360 [eJOI 2024] 足球决斗 / CF Duels

a_123_a约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年7月3日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 3 分钟
题目
P12360

版本

  1. v2当前
  2. v1

显然有但我们知道的信息越多时,我们越能知道我们是否能够获得冠军,满足单调性,所以我们考虑二分答案。 在二分的 check⁡\operatorname{check} 当中,我们只需要知道我们是否一定获胜。考虑最坏情况,对于我们不知道情况的体育场,我们认为对方没有上场的球员最强在奖金最大的体育场上,次强在奖金次最大上,以此类推。这就是最坏情况。所以我们 check⁡\operatorname{check} 就只需要判断在最坏情况中是否可以获得冠军。时间复杂度 O⁡(nlog2n)\operatorname {O}(nlog^2n)。

C++
#include<bits/stdc++.h>
using namespace std;
#define N 50005
#define intl long long
#define For(i,a,b) for(intl i=a;i<=b;i++)
#define deo(i,a,b) for(intl i=a;i>=b;i--)
intl read() {
	intl x=0,k=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch == '-') k=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*k;
}
intl n,p[N],b[N],a[N],sum;
bool check(intl x) {
	multiset<intl> qwe,qaz,ys;//要用multiset,因为对方球员的等级可能有相同的,或者您使用优先队列
	set<pair<intl,intl>> st;//保存所有体育场的奖金数和对方球员的等级
	For(i, 1, n) ys.insert(a[i]);//己方
	For(i, 1, x) st.insert({-p[i],b[i]});//确定的体育场
	For(i, x+1, n) qwe.insert(-b[i]),qaz.insert(-p[i]);
	For(i, x+1, n) st.insert({*qaz.begin(),-*qwe.begin()}),qaz.erase(qaz.begin()),qwe.erase(qwe.begin());//对于不确定的我们按奖金大小分配相应位次的球员
	intl res = 0;
	for(auto tmp:st){
		auto it = ys.upper_bound(tmp.second);
		if(it != ys.end()) res += -tmp.first, ys.erase(it);
	}
	return res > sum/2;//当我们在最坏情况下的奖金数已经大于总奖金的一半时,我们一定可以获得冠军
}
int main() {
	n = read();
	For(i, 1, n) p[i] = read(), sum += p[i];
	For(i, 1, n) b[i] = read();
	For(i, 1, n) a[i] = read();
	intl l = 0, r = n, ans = -1;
	while(l < r) {
		intl mid = (l+r)>>1;
		if(check(mid)) ans = r = mid;
		else l = mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

原文