0
点赞
收藏
分享

微信扫一扫

Codeforces Round #698 (Div. 2)C. Nezzar and Symmetric Array

small_Sun 2022-09-26 阅读 174

地址:​​http://codeforces.com/contest/1478/problem/C​​

解析:
可以发现,每一个ai与其他数进行运算时,结果都为绝对值较大的那一方*2

那么先对d[]进行排序

从最大的d开始,那么不难求出当前的最大amaxx1:(d/2)/n

然后是第二大d,求出第二大amaxx2:(d/2-amaxx1)/(n-1)

第三大:(d/2-amaxx1-amaxx2)/(n-2)

.....

以此类推,如果出现某一次算出来的ai<=0或者不能整除的,一定为NO

注意,d[]里的每一个数一定是成对出现的,提前判断一下。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
const int maxn = 3e5+50;
const int inf=99999999;
typedef long long ll;
ll d[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
map<ll,int>mp;
int n ;
cin>>n;
int ok = 0 ;
for(int i=1;i<=2*n;i++)
{
cin>>d[i];
mp[d[i]]++;
if(d[i]%2!=0)
{
ok=1;
}
}
for(auto i = mp.begin();i!=mp.end();i++)
{
if(i->second!=2)
{
ok=1;break;
}
}
if(ok)
cout<<"NO"<<endl;
else
{
sort(d+1,d+1+2*n);
ll maxx=0;
int cnt = n;
for(int i=2*n;i>=1;i-=2)
{
ll md = (d[i]/2-maxx)/cnt;
if((d[i]/2-maxx)%cnt!=0||(d[i]/2-maxx)<=0)
{
ok=1;break;
}
maxx +=md;
cnt--;
}
if(ok)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
return 0;
}
//ababab

 



举报

相关推荐

0 条评论