Author: loop3r
Date: 20260224
tag: 枚举
link: https://www.luogu.com.cn/problem/P2141问题描述
分析
依次枚举集合中的两个数字之和能够构成的集合中的另一个数。
参考代码
cpp
#include<bits/stdc++.h>
using namespace std;
const int N = 20010;
int exist[N], total[N];
int main() {
int a[110];
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
exist[a[i]] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
total[a[i] + a[j]]++;
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (exist[i] && total[i] > 0) cnt++;
}
cout << cnt << endl;
return 0;
}