作者驾到
2026-08-05 15:20:49
发布于:陕西
0阅读
0回复
0点赞
这是正经题解
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);//提高cin/cout速度
cin.tie(0);
int n;
cin >> n;
vector<int>a(n, 0);
set<int>b;//哈希集合
//双重循环遍历
for(int i = 0 ; i< n; i++){
cin >> a[i];
b.insert(a[i]);
}bool is_hsz = 1;
for(int i = 0 ; i < n; i++){
for(int j = i + 1; j < n; j++){
int a1 = a[i];
int a2 = a[j];
bool inS = b.count(a1 + a2) > 0;//和是否存在
bool inD = b.count(abs(a1 - a2)) > 0;//距离是否存在
if(!inS && !inD){
is_hsz = 0;
break;
}
}if(!is_hsz) break;
}if(is_hsz) cout << "Yes";
else cout << "No";
}
这里空空如也








有帮助,赞一个