欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

poj2231

发布时间:2025/5/22 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 poj2231 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

简单题

View Code #include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 10006

int f[maxn];

int main()
{
//freopen("t.txt", "r", stdin);
int n;
scanf(
"%d", &n);
for (int i = 0; i < n; i++)
scanf(
"%d", &f[i]);
sort(f, f
+ n);
long long ans = 0, sum = 0;
for (int i = 1; i < n; i++)
{
sum
+= ((long long)(f[i] - f[i - 1])) * i;
ans
+= sum;
}
printf(
"%lld\n", ans * 2);
return 0;
}

转载于:https://www.cnblogs.com/rainydays/archive/2011/05/27/2059736.html

总结

以上是生活随笔为你收集整理的poj2231的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。