欲由4根木棒组成一个正三角形,则必有2根长度相等,且另外2根长度之和,等于前2根相等的木棒的长度。
#include <cstdio>
#include <algorithm>
using LL = long long;
const int N = 1e5 + 5, mod = 1e9 + 7;
int n, a[N], cnt[N];
int main()
{
scanf("%d", &n);
int min = 1e9, max = -1e9;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
min = std::min(min, a[i]);
max = std::max(max, a[i]);
}
LL ans = 0;
for (int i = min; i <= max; i++) {
if (cnt[i] >= 2) {
LL times = cnt[i] * (cnt[i] - 1) / 2 % mod;
for (int j = min; j <= i / 2; j++) {
if (j != i - j && cnt[j] >= 1 && cnt[i - j] >= 1) ans += times * cnt[j] * cnt[i - j] % mod;
else if (j == i - j && cnt[j] >= 2) ans += times * (cnt[j] * (cnt[j] - 1) / 2) % mod;
}
}
}
printf("%lld", ans%mod);
return 0;
}
标签:cnt,妖梦,min,木棒,max,int,P3799,mod
From: https://www.cnblogs.com/pangyou3s/p/18016911