标签:lan html its sizeof rip printf 正整数 sort diff
社交网络中我们给每个人定义了一个“活跃度”,现希望根据这个指标把人群分为两大类,即外向型(outgoing,即活跃度高的)和内向型(introverted,即活跃度低的)。要求两类人群的规模尽可能接近,而他们的总活跃度差距尽可能拉开。
输入第一行给出一个正整数N(2≤N≤10?5??)。随后一行给出N个正整数,分别是每个人的活跃度,其间以空格分隔。题目保证这些数字以及它们的和都不会超过2?31??。
按下列格式输出:
Outgoing #: N1
Introverted #: N2
Diff = N3
其中N1
是外向型人的个数;N2
是内向型人的个数;N3
是两群人总活跃度之差的绝对值。
10
23 8 10 99 46 2333 46 1 666 555
Outgoing #: 5
Introverted #: 5
Diff = 3611
13
110 79 218 69 3721 100 29 135 2 6 13 5188 85
Outgoing #: 7 Introverted #: 6 Diff = 9359
机智的我双开数组代表 + if 讨论 1A
鲁老师的学生不许抄我的,我会被挂的。
#include <bits/stdc++.h> using namespace std; typedef long long LL; LL acv[100100],sum[100100]; int main() { memset(acv,0,sizeof(acv)); memset(sum,0,sizeof(sum)); int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&acv[i]); } sort(acv+1,acv+1+n); sum[0]=0; for(int i=1;i<=n;i++){ sum[i] = sum[i-1]+acv[i]; } int a1 = n/2; int b1 = n-n/2; LL diff1 = 0; diff1 = sum[n] - 2*sum[a1]; int b2 = n/2; int a2 = n-n/2; LL diff2 = 0; diff2 = sum[n] - 2*sum[a2]; if(diff1>diff2){ printf("Outgoing #: %d\n",b1); printf("Introverted #: %d\n",a1); printf("Diff = %lld\n",diff1); } else { printf("Outgoing #: %d\n",b2); printf("Introverted #: %d\n",a2); printf("Diff = %lld\n",diff2); } }
标签:lan html its sizeof rip printf 正整数 sort diff
原文地址:http://www.cnblogs.com/masterchd/p/7886615.html