码迷,mamicode.com
首页 > 其他好文 > 详细

luogu P3799 妖梦拼木棒

时间:2017-06-21 23:10:26      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:长度   etc   div   lld   ref   lan   argv   argc   har   

二次联通门 : luogu P3799 妖梦拼木棒

 

 

 

/*
    luogu P3799 妖梦拼木棒
    
    用一个桶存下所有的木棒
    
    美剧两根短的木棒长度
    
    后随便乘一乘就 好了。。 

*/
#include <algorithm>
#include <cstdio>

#define Mod 1000000007

#define Max 5000

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    while (word < 0 || word > 9)
        word = getchar ();
    while (word >= 0 && word <= 9)
    {
        now = now * 10 + word - 0;
        word = getchar ();
    }
}


int N;

long long count[Max << 1];
long long Answer;

int main (int argc, char *argv[])
{
    read (N);
    int x;
    for (register int i = 1; i <= N; i ++)
    {
        read (x);
        count[x] ++;
    }
        
    for (register int i = 1; i <= Max; i ++)
        for (register int j = i; j <= Max; j ++)
        {
            if (i + j > Max)
                break;
            if (i == j)
            {
                if (count[i] >= 2 && count[i << 1] >= 2)
                    Answer = (Answer + count[i] * (count[i] - 1) / 2LL % Mod * (count[i << 1] * (count[i << 1] - 1) / 2 % Mod)) % Mod;    
            }
            else
                if (count[i] >= 1 && count[j] >= 1 && count[i + j] >= 2)
                    Answer = (Answer + (count[i] * count[j] % Mod * (count[i + j] * (count[i + j] - 1) / 2)% Mod)) % Mod;
                
        }
    
    printf ("%lld", Answer);
    return 0;
}

 

luogu P3799 妖梦拼木棒

标签:长度   etc   div   lld   ref   lan   argv   argc   har   

原文地址:http://www.cnblogs.com/ZlycerQan/p/7061897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!