admin管理员组

文章数量:1530028

https://codeforces/problemset/problem/1399/C

 

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,res=0;
		int a[100];
		cin>>n;
        for(int i=0;i<n;i++) cin>>a[i];
		int t[100];
		for(int i=2;i<=n*2;i++){//枚举每两个人可能的体重之和
			memset(t,0,sizeof t);
			int ans=0;
			for(int j=0;j<n;j++) t[a[j]]++;//每次都要重新统计各个体重的人数
			//数组的时间复杂度是O(1),map的时间复杂度是__,用map会超时
			for(int j=1;j<=n;j++){
				if(i-j>n||i-j<1) continue;
				if(i-j==j){
				    ans+=t[j]/2;
					t[j]%=2;
					continue;
				}
				int x=min(t[j],t[i-j]);
				ans+=x;
				t[j]-=x;
				t[i-j]-=x;
			}
			res=max(res,ans);
		}
		cout<<res<<'\n';
	}
	return 0;
}

本文标签: 贪心暴力Boatscompetition