poj 2231 Moo Volume
来源:互联网 发布:人肉俄罗斯转盘 知乎 编辑:程序博客网 时间:2024/06/05 15:06
http://poj.org/problem?id=2231
在一个数轴上给出n个点。求这n个点 每个点到其他点距离的和的和,很简单的规律题,不难发现,每2个点之间的长度 都对最终答案贡献2次。
#include<iostream>#include<cstring>#include<algorithm>using namespace std;long long int a[11111];long long int ans;int main(){int n;while(cin>>n){//memset(ans,0,sizeof(ans));int i;for(i=1;i<=n;i++)cin>>a[i];sort(a+1,a+1+n);int j;long long int ans=0;for(i=1;i<=n;i++){for(j=i+1;j<=n;j++){ans+=(a[j]-a[i])*2;}}cout<<ans<<endl;} return 0;}
阅读全文
0 0
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume
- POJ -- 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume
- poj 2231Moo Volume
- POJ 2231 Moo Volume
- POJ 2231-Moo Volume
- poj 2231 Moo Volume
- poj 2231 Moo Volume
- POJ 2231 Moo Volume (暴力)
- poj 杂题 - 2231 Moo Volume
- POJ 2231:Moo Volume【细心】
- POJ 2231 Moo Volume【求和】
- POJ 2231 Moo Volume 笔记
- poj 1035 Spell checker
- UVA
- SD卡文件读写
- mysql字段text类型的使用
- 有关C++ 实现时extern 和const的问题
- poj 2231 Moo Volume
- 小程序合集1(素数、闰年、乘法表)
- centos 怎么用 基本知识
- pandas中利用get_dummies()进行独热编码(One-Hot encoding)
- DGHLDKFHLDFH
- hdu 3466 Proud Merchants
- WAV音频文件
- Exection(二)
- photoshop入门1