题解:AT_abc409_c [ABC409C] Equilateral Triangle
xiaoyin2011 · · 题解
AT_abc409_c [ABC409C] 等边三角形 题解
题目链接
题目大意
有一个周长
问有多少对递增且互不相同的三个数字
思路及实现
根据中学几何知识,易得等边三角形的中心在圆心,同时三个弦对应弧相等。
此时将
发现这个公差一定是
于是此时枚举三个数
但是一个三角形会在这里计算三次,所以最后除以三去重。
AC Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, L, d[300005], cnt[300005], ans = 0;
int main()
{
scanf("%lld%lld", &N, &L);
d[1] = 0;
for (int i = 1; i <= N - 1; i++)
{
scanf("%lld", &d[i + 1]);
d[i + 1] += d[i];
d[i + 1] %= L;
}
for (int i = 1; i <= N; i++)
cnt[d[i]]++;
if (L % 3 != 0)
{
printf("0\n");
return 0;
}
for (int i = 0; i < L; i++)
ans += cnt[(i - L / 3 + L) % L] * cnt[i] * cnt[(i + L / 3 + L) % L];
printf("%lld\n", ans / 3);
return 0;
}