Codeforces Round #661 (Div. 3) C.Boats CompetitionCompetition
程序员文章站
2022-06-23 13:17:39
题目链接思路:首先预处理出所有可能的两两相加得到的答案,然后去重处理,标记初始数组中每个元素出现的次数,并标记当前元素存在,然后枚举预处理后的两元素和标记元素是否存在。代码:#include#define int long long#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);const int N=2e5+7;const int M=2e4+5;const doubl...
题目链接
思路:
首先预处理出所有可能的两两相加得到的答案,然后去重处理,标记初始数组中每个元素出现的次数,并标记当前元素存在,然后枚举预处理后的两元素和标记元素是否存在。
代码:
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e5+7;
const int M=2e4+5;
const double eps=1e-8;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926;
using namespace std;
int vis[N],a[N],b[N],c[N];
signed main()
{
IOS;
int t;
cin>>t;
while(t--)
{
int n,ma=-1000,minb=1e9+7,ans=0;
cin>>n;
vector<int>vec;
memset(vis,0,sizeof vis);
memset(b,0,sizeof b);
for(int i=1;i<=n;i++)
{
cin>>a[i];
vis[a[i]]=1;
b[a[i]]++;
}
sort(a+1,a+1+n);
int cnt=0;
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
{
vec.push_back(a[i]+a[j]);
}
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
int k=vec.size();
for (int i=0;i<k;i++)
{
int t=0;
for (int j=1;j<=n;j++)
{
int kp=vec[i]-a[j];
if (kp>0&&vis[kp])
{
if(kp==a[j]&&(b[kp]-c[kp])<=1)
{
continue;
}
int x=min(b[a[j]]-c[a[j]],b[kp]-c[kp]);
x=max(x,0LL);
if(kp==a[j])
{
t+=x/2;
}
else
{
t += x;
}
c[a[j]]+=x;
c[kp]+=x;
}
}
memset(c,0,sizeof c);
ans=max(ans,t);
}
cout<<ans<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/ACkingdom/article/details/107853537
推荐阅读
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
CodeForces 1324 - Codeforces Round #627 (Div. 3)
-
Codeforces Round #650 (Div. 3) B. Even Array
-
Codeforces Round #686 (Div. 3) A. Special Permutation
-
A. Add Odd or Subtract Even(思维题) Codeforces Round #624 (Div. 3)
-
Codeforces Round #656 (Div. 3) (C、D题)
-
Codeforces Round #686 (Div. 3) F. Array Partition
-
A. Circle of Students(遍历匹配)Codeforces Round #579 (Div. 3)
-
Codeforces Round #656 (Div. 3) A. Three Pairwise Maximums
-
Codeforces Round #686 (Div. 3)_A. Special Permutation