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

UVa11300 - Spreading the Wealth

时间:2015-09-19 06:08:53      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

解题思路:现在是北京时间凌晨1:33,好累,懒得分析了,一点要注意,%I64d在UVa上

     提交是错误的。WA了好几发,用%lld.刘汝佳白皮书《训练指南》第四页,晚安。

    

技术分享
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 #define LL long long
 6 const int maxn = 1000005;
 7 LL A[maxn], C[maxn], n, tot, m;
 8 int main()
 9 {
10     while(~scanf("%lld", &n))
11     {
12         tot = 0;
13         for(int i = 1; i <= n; i++)
14         {
15             scanf("%lld", &A[i]);
16             tot += A[i];
17         }
18         m = tot / n;
19         C[0] = 0;
20         for(int i = 1; i <= n; i++) C[i] = C[i-1]+A[i]-m;
21         sort(C+1, C+n+1);
22         tot = 0;
23         m = C[(n+1)/2];
24         for(int i = 1; i <= n; i++) tot += abs(C[i]-m);
25         printf("%lld\n", tot);
26     }
27     return 0;
28 }
View Code

 

UVa11300 - Spreading the Wealth

标签:

原文地址:http://www.cnblogs.com/loveprincess/p/4820827.html

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