From 842ce30e1f30042cc41825fbcf67e3768fcebdf4 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 21 Nov 2021 18:58:58 +0800 Subject: [PATCH] =?UTF-8?q?P2141=20[NOIP2014=20=E6=99=AE=E5=8F=8A=E7=BB=84?= =?UTF-8?q?]=20=E7=8F=A0=E5=BF=83=E7=AE=97=E6=B5=8B=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R63301836 --- Luogu/P2141/P2141.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Luogu/P2141/P2141.cpp diff --git a/Luogu/P2141/P2141.cpp b/Luogu/P2141/P2141.cpp new file mode 100644 index 00000000..3e9cd156 --- /dev/null +++ b/Luogu/P2141/P2141.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +int n, a[105], ans; +bool vis[105]; + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + sort(a + 1, a + 1 + n); + for (int i = 1; i < n - 1; i++) { + for (int j = i + 1; j < n; j++) { + for (int k = j + 1; k <= n; k++) { + if (a[i] + a[j] == a[k] && !vis[k]) { + ans++; + vis[k] = true; + } + } + } + } + cout << ans << endl; + return 0; +}