社区讨论
二十分求助
P2141[NOIP 2014 普及组] 珠心算测验参与者 4已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo3pvkx9
- 此快照首次捕获于
- 2023/10/24 10:38 2 年前
- 此快照最后确认于
- 2023/11/02 11:37 2 年前
CPP
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n - 1, [](int a, int b) -> bool { return a < b; });
int s = 0;
for (int i = 0; i < n; i++) {
int sum = a[i], previous = -1;
for (int j = 0; j < i; j++) {
int n1 = a[j];
if (n1 == previous) {
continue;
} else {
previous = n1;
}
if (n1 > sum / 2) break;
for (int k = j + 1; k < i; k++) {
int n2 = a[k];
if (n1 != n2 && n1 + n2 == sum) {
s++;
}
}
}
}
cout << s << endl;
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...