首页 > 其他 > 详细

Pairwise Sum and Divide

时间:2017-09-28 21:35:02      阅读:243      评论:0      收藏:0      [点我收藏+]

题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305

统计1和2的数量

1-1是2 1-x(不为1)是1 2-2是1

时间复杂度O(n)

#include<iostream>
using namespace std;

const int maxn=1e5+5;
int a[maxn],n,n1=0,n2=0;

int main()
{
    __int64 sum;
    
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==1)
            n1++;
        else if(a[i]==2)
            n2++;
    }
    int n11=n1*(n1-1)/2,n1x=n1*(n-n1),n22=n2*(n2-1)/2;
    sum=n11*2+n22+n1x;
    cout<<sum;
}

 

Pairwise Sum and Divide

原文:http://www.cnblogs.com/NDKY9/p/7608661.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!