正版题解
2025-07-09 11:34:17
发布于:广东
2阅读
0回复
0点赞
正版题解
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int count = 0;
unordered_set<int> seen;
seen.insert(a[0]);
for (int i = 1; i < n; ++i) {
int current = a[i];
bool found = false;
// 检查是否存在x, y, z在seen中使得x + y + z = current
// 转换为是否存在x, y在seen中,使得current - x - y也在seen中
for (int x : seen) {
if (found) break;
for (int y : seen) {
int target = current - x - y;
if (seen.find(target) != seen.end()) {
found = true;
break;
}
}
}
if (found) {
count++;
}
seen.insert(current);
}
cout << count << endl;
return 0;
}
这里空空如也
有帮助,赞一个