POJ 2231 Moo Volume【求和】
来源:互联网 发布:软件研发管理体系 编辑:程序博客网 时间:2024/06/07 00:50
Moo Volume
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluDescription
Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are making too much noise.
FJ's N cows (1 <= N <= 10,000) all graze at various locations on a long one-dimensional pasture. The cows are very chatty animals. Every pair of cows simultaneously carries on a conversation (so every cow is simultaneously MOOing at all of the N-1 other cows). When cow i MOOs at cow j, the volume of this MOO must be equal to the distance between i and j, in order for j to be able to hear the MOO at all. Please help FJ compute the total volume of sound being generated by all N*(N-1) simultaneous MOOing sessions.
FJ's N cows (1 <= N <= 10,000) all graze at various locations on a long one-dimensional pasture. The cows are very chatty animals. Every pair of cows simultaneously carries on a conversation (so every cow is simultaneously MOOing at all of the N-1 other cows). When cow i MOOs at cow j, the volume of this MOO must be equal to the distance between i and j, in order for j to be able to hear the MOO at all. Please help FJ compute the total volume of sound being generated by all N*(N-1) simultaneous MOOing sessions.
Input
* Line 1: N
* Lines 2..N+1: The location of each cow (in the range 0..1,000,000,000).
* Lines 2..N+1: The location of each cow (in the range 0..1,000,000,000).
Output
There are five cows at locations 1, 5, 3, 2, and 4.
Sample Input
515324
Sample Output
40
Hint
INPUT DETAILS:
There are five cows at locations 1, 5, 3, 2, and 4.
OUTPUT DETAILS:
Cow at 1 contributes 1+2+3+4=10, cow at 5 contributes 4+3+2+1=10, cow at 3 contributes 2+1+1+2=6, cow at 2 contributes 1+1+2+3=7, and cow at 4 contributes 3+2+1+1=7. The total volume is (10+10+6+7+7) = 40.
There are five cows at locations 1, 5, 3, 2, and 4.
OUTPUT DETAILS:
Cow at 1 contributes 1+2+3+4=10, cow at 5 contributes 4+3+2+1=10, cow at 3 contributes 2+1+1+2=6, cow at 2 contributes 1+1+2+3=7, and cow at 4 contributes 3+2+1+1=7. The total volume is (10+10+6+7+7) = 40.
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define MS(x,y)memset(x,y,sizeof(x))typedef long long LL;const int INF=0x7ffffff;const int M=1e4+1;int i,j,n,k,m;int num[M];int main(){ scanf("%d",&n); rep(i,0,n)scanf("%d",&num[i]); sort(num,num+n); LL sum=0; rep(i,0,n){ rep(j,0,i)sum+=num[i]-num[j]; rep(j,i+1,n)sum+=num[j]-num[i]; } printf("%lld\n",sum); 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 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 笔记
- tencent-wechat/phxsql
- 排序算法:快速排序
- PointToPointNetDevice doesn't support TapBridgeHelper
- 自定义按钮--Selector
- ==与equal的区别
- POJ 2231 Moo Volume【求和】
- 自定义控件 ——可拖动测量尺子
- Git分布式版本控制系统 基本介绍
- PAT 1003. Emergency (25)(俩点间最短路径)
- V4L2视频应用程序编程架构
- Android accessibilityserver
- Android编译过程详解(二)
- sessionKey/tokenKey相关知识点收集汇总
- Android学习系列(4)--App自适应draw9patch不失真背景