大概思路就是,随便选一个数看是否存在相反数,并且两者数量加和是否为n就可以判断是否存在所需数组
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vll=vector<ll>;
using vvll=vector<vector<ll>>;
using vc=vector<char>;
using vs=vector<string>;
using vb=vector<bool>;
using vpii=vector<pii>;
using vpll=vector<pll>;
const int INF=1e9;
const ll LINF=4e18;
const int MOD=1e9+7;
const int MOD2=998244353;
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ral(x) x.rbegin(),x.rend()
#define fi first
#define se second
#define fix(x) fixed<<setprecision(x)
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
ll qpow(ll a,ll b,ll mod=MOD){
ll res=1;
a%=mod;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
ll modinv(ll a,ll p=MOD){
return qpow(a,p-2,p);
}
struct Node{
int a,b;
bool operator<(const Node &y)const{
return b>y.b;
}
};
void solve(){
int n;cin>>n;
int a;
bool aa=0;//是否有-a
int c1=0,c2=0;//a有多少个,-a有多少个
for(int i=0;i<n;++i){
int b;cin>>b;
if(b==0){//有0就一定不行
cout<<"NO";
return;
}
if(i==0)a=b;//取第一个数为a
else if(b==-a)aa=1;//有-a
if(b==a)++c1;
else if(b==-a)++c2;
}
if(aa&&c1+c2==n){//存在一对相反数,并且数量和为n
cout<<"NO";
return;
}
cout<<"YES";
}
int main(){
IOS;
int _=1;//cin>>_;
while(_--){
solve();
}
return 0;
}

京公网安备 11010502036488号