题目传送门

一、思路总结

  1. 前方有坑!需要理解 \(5=1+4=2+3\),但\(5\)只算一次的道理。

  2. 数组+桶记录使用过。

二、完整代码

#include <bits/stdc++.h>

using namespace std;
// 这题30分的一般都是没有去重……1+4=5和2+3=5算同一个……
//这道题还是挺有意思的,注意,前方有坑!需要理解 5=1+4=2+3,但5只算一次的道理。
const int N = 110;
int n;
int a[N];
bool b[N]; //标识已使用
int cnt;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i];

    //暴力三层循环+标识数组
    for (int i = 1; i < n; i++)
        for (int j = i + 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                if (a[k] == a[i] + a[j] && !b[k]) cnt++, b[k] = true;

    printf("%d", cnt);
    return 0;
}

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-11-08
  • 2021-06-09
  • 2022-02-18
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案