题意
Sol
发现abcdef是互不相关的
那么meet in the middle一下。先算出abc的,再算def的
注意d = 0的时候不合法(害我wa了两发。。)
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 101, SS = 2e6 + 10;
map<LL, LL> mp;
int N;
LL a[MAXN], ans;
int a1[SS], c1, a2[SS], c2, cnt[SS];
int main() {
// ios::sync_with_stdio(false);
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
sort(a + 1, a + N + 1);
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
for(int k = 1; k <= N; k++)
a1[++c1] = a[i] * a[j] + a[k];
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
for(int k = 1; k <= N; k++)
if(a[i] != 0) a2[++c2] = a[i] * (a[j] + a[k]);
sort(a1 + 1, a1 + c1 + 1);
sort(a2 + 1, a2 + c2 + 1);
for(int i = 1, j = 1; i <= c2; i++) {
if(i != 1 && (a2[i] == a2[i - 1])) {cnt[i] = cnt[i - 1]; continue;}
while(a1[j] <= a2[i] && j <= c1) {
if(a1[j] == a2[i]) cnt[i]++;
j++;
}
}
for(int i = 1; i <= c2; i++) ans += cnt[i];
cout << ans;
return 0;
}
原文地址:https://www.cnblogs.com/zwfymqz/p/10246752.html
时间: 2024-11-02 04:12:20