枚举两个小的长度,不知道问题出在哪
查看原帖
枚举两个小的长度,不知道问题出在哪
389844
XjascodoixjqoinOI楼主2020/11/26 17:34

i,j来枚举两个小的木棍的长度

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 10010, mod = 1e9 + 7, M = 5010;

long long cnt[M];
int a[N];
int n;
long long res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ )
    {
        scanf("%d", a + i);
        cnt[a[i]] ++;
     }
     for (int i = 0; i < 5010; i ++ )
         for (int j = i; j < 5010; j ++ )
         {
             if (i + j >= 5000) continue;
             if (i != j)
             {
                 if (cnt[i] && cnt[j] && cnt[i + j] > 1)
                {
                    long long x1 = cnt[i], x2 = cnt[j], x3 = cnt[i + j];
                    res = (res + ((x1 * x2) % mod) * (x3 * (x3 - 1) / 2) % mod) % mod;
                }
             }
             else
             {
                 if (cnt[i] > 1 && cnt[i + i] > 1)
                    res = (res + ((cnt[i] * (cnt[i] - 1) / 2) % mod) * (cnt[i + i] * (cnt[i + i] - 1) / 2) % mod) % mod;
             }
         }
     res %= mod;
     printf("%lld\n", res);
     system("pause");
     return 0;
}

2020/11/26 17:34
加载中...