1 solutions
-
0
思路
1 2 3 4 5 6
这个数组,其中6 = 1 + 5 = 2 + 3 但是只计数一次
b数组用来表示输入过哪些数字 c数组用来表示之前是否使用过
ac code
#include<bits/stdc++.h> typedef long long LL; using namespace std; const int N = 1e5 + 5; int a[N],b[N],c[N]; int n,cnt; int main () { cin >> n; for(int i = 1;i <= n;++ i) { cin >> a[i]; b[a[i]] = 1; } for(int i = 1;i <= n;++ i) { for(int j = i + 1;j <= n;++ j) { int tmp = a[i] + a[j]; if(b[tmp] == 1 && c[tmp] == 0) { cnt ++; c[tmp] = 1; } } } cout << cnt; return 0; }
- 1
Information
- ID
- 7016
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 78
- Accepted
- 18
- Uploaded By