cf-1749c 求助
  • 板块学术版
  • 楼主Cosine_Chen
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/2/2 18:50
  • 上次更新2025/2/3 00:38:50
查看原帖
cf-1749c 求助
1512885
Cosine_Chen楼主2025/2/2 18:50

题目

基本思路是

A尽可能删去可操作数当中大的数,B删去1,如果能在1删完前操作结束则A获胜

不知道为什么一直卡在test3,求大佬解惑

#include<bits/stdc++.h>
#define el '\n'
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);

using namespace std;

void solve(){
	int n;
	cin >> n;
	vector <int> a(n+1, 0);
	int cnt1 = 0;
	for(int i=1; i<=n; i++){
		cin>> a[i];
        //统计1的个数
		if(a[i] == 1)
			cnt1++;
	}
	sort(a.begin()+1, a.end());
  //易知操作数不能大于n的一半
	int ans = min(cnt1, n&1 ? n/2+1 : n/2);
	while(1){
		int t = 1, l=1, r=n;
		while(l <= r){
			int mid = (l+r)/2;
			if(a[mid] <= ans){
				l = mid+1;
				t = mid;
			}
			else
				r = mid-1;
		}
//		cout << t << ' ' << ans << '|';
        //1-t为基于ans(k)的可操作区域A执行ans次操作,
        //B最少可执行ans-1次操作
		if((t&1 ? t/2+1 : t/2) < ans)
			ans--;
		else
			break;
	}
	cout << ans << el;
	return ;
}

int main(){
	IOS
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
	return 0;
}

//1 6 1 1 1 1 1 6
//1 6 1 1 1 4 5 6
//1 6 6 5 4 3 2 1
//1 5 1 1 1 3 4 
//1 5 1 1 2 2 4 
//1 3 1 1 2
2025/2/2 18:50
加载中...