跳到正文

题解

题解:P14783 [NERC 2025] Battle of Arrays

YL_LiLuo_SK约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年12月19日
收录
2025年12月20日
更新
2026年11月13日
篇幅
约 2 分钟
题目
P14783

版本

  1. v1当前

现在最大值是确定的,显然我们想让对方的这个最大值越小越好,所以我们就选自己的最大值,一直这样下去,模拟即可,用优先队列维护最大值。

Code:

C++
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fs first
#define sc second
#define il inline
#define re register
using namespace std;
il int read()
{
	re int x=0;
	re int ff=1;
	re char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
			ff=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*ff;
}
const int N=1e5+6;
int t,n,m;
signed main()
{
	t=read();
	for(;t;t--){
		priority_queue<int,vector<int>,less<int> > a,b;
		n=read(),m=read();
		for(re int i=1;i<=n;i++)
			a.push(read());
		for(re int j=1;j<=m;j++)
			b.push(read());
		re int flag=0;
		while(1){
			re int x=b.top(),y=a.top();
			b.pop(),a.pop();
			if(x>y)b.push(x-y);
			if(b.empty())
				break;
			x=b.top();
			if(x<y)a.push(y-x);
			if(a.empty()){
				flag=1;
				break;
			}
		}
		if(flag)printf("Bob\n");
		else printf("Alice\n");
	}
	return 0;
}
原文
存档评论1 条抓取于