Moo Volume POJ - 2231
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
* Lines 2..N+1: The location of each cow (in the range 0..1,000,000,000).
Output
Sample Input
5
1
5
3
2
4
Sample Output
40
Hint
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<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cctype>
using namespace std;
long long a[];
int main() {
int n;
while(scanf("%d",&n)!=EOF){
for (int i= ;i<n ;i++)
scanf("%lld",&a[i]);
sort(a,a+n);
long long sum=;
for (int i= ;i<n ;i++ )
sum+=(n--i)*(a[n--i]-a[i]);
printf("%lld\n",sum*);
}
return ;
}
Moo Volume POJ - 2231的更多相关文章
- BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声
1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 723 Solved: 346[ ...
- BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )
一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...
- Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏
Moo Volume Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22104 Accepted: 6692 Descr ...
- POJ 2231 Moo Volume
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description Farmer Jo ...
- Poj 2232 Moo Volume(排序)
题目链接:http://poj.org/problem?id=2231 思路分析:先排序,再推导计算公式. 代码如下: #include <iostream> #include <a ...
- B - Moo Volume
Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are ...
- 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)
http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...
- bzoj 1679: [Usaco2005 Jan]Moo Volume 牛的呼声【枚举】
直接枚举两两牛之间的距离即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
随机推荐
- 洛谷 [P2701] 巨大的牛棚
首先,本题是一道最大子矩阵问题,且m,n较小,可以使用DP做, 与 洛谷 [P1387]最大正方形 做法相同. #include <iostream> #include <cstdi ...
- 安装基于 Linux 发行版的重要事项(流程指引)
安装基于 Linux 发行版的重要事项(Install important issues based on the Linux distribution. (Process guidance)) 1. ...
- Windows Server 2016-WinSer2016 Active Directory新增功能
Windows Server 2016 Active Directory 域服务 (AD DS)新增很多功能用来提升Active Directory域及组织环境安全等,并帮助他们面向云的部署或混合部署 ...
- Windows 系统下安装 dig 命令
dig是一个Linux下用来DNS查询信息的小工具,dig全称是Domain Information Groper,与nslookup类似,但比nslookup功能更强大.Windows只有nsloo ...
- CENTOS6.6下nmon的监控
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn Installing Nmon By default nmon is ...
- 利用Jsonp实现跨域请求,spring MVC+JQuery
1 什么是Jsonp? JSONP(JSON with Padding)是数据格式JSON的一种"使用模式",可以让网页从别的网域要数据.另一个解决这个问题的新方法是跨来源资源共享 ...
- 彻底理解 Android 中的阴影
如果我们想创造更好的 Android App,我相信我们需要遵循 Material Design 的设计规范.一般而言,Material Design 是一个包含光线,材质和投影的三维环境.如果我们想 ...
- php环境下所有的配置文件以及作用
以下主要是针对linux下的目录(windows也是一样,文件名都一样) Apache:etc/httpd.conf PHP:etc/php.ini (Apache 正在运行的 PHP 版本) M ...
- hdu3480 Division(dp平行四边形优化)
题意:将n个数分成m段,每段的代价为最大值减最小值的平方,为代价最小是多少n<=10000 ,m<=5000 题解:先拍好序,从小到大,这样绝对是花费最小的,不过怎么样来做呢?一定很容易想 ...
- Scrapy-多层爬取天堂图片网
1.根据图片分类对爬取的图片进行分类 开发者选项 --> 找到分类地址 爬取每个分类的地址通过回调函数传入下一层 name = 'sky'start_urls = ['http: ...