POJ 2231 Moo Volume
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
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<iostream>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 10005
int c[N];
int main()
{
int n,i,j;
long long ans;
while(scanf("%d",&n)!=EOF)
{
ans=;
for(i=;i<n;i++)
{
scanf("%d",&c[i]);
}
sort(c,c+n);
for(i=;i<n-;i++)
{
for(j=i+;j<n;j++)
{
ans+=*abs(c[i]-c[j]);
}
}
printf("%lld\n",ans);}
return ;
}
POJ 2231 Moo Volume的更多相关文章
- Poj 2232 Moo Volume(排序)
题目链接:http://poj.org/problem?id=2231 思路分析:先排序,再推导计算公式. 代码如下: #include <iostream> #include <a ...
- BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声
1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 723 Solved: 346[ ...
- POJ 2010 Moo University - Financial Aid( 优先队列+二分查找)
POJ 2010 Moo University - Financial Aid 题目大意,从C头申请读书的牛中选出N头,这N头牛的需要的额外学费之和不能超过F,并且要使得这N头牛的中位数最大.若不存在 ...
- 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 ...
- Moo Volume POJ - 2231
Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are ...
- poj -2010 Moo University - Financial Aid (优先队列)
http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...
- 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 ...
随机推荐
- WIN10使用管理员权限运行VS2013
学习WCF时出现报错-- 其他信息: HTTP 无法注册 URL http://+:8083/User/.进程不具有此命名空间的访问权限(有关详细信息,请参见 http://go.microsoft. ...
- OpenVPN客户端证书合并到配置文件中
这里只讲OpenVPN客户端证书合并到配置文件中,避免文件太多,管理不便! 生成的客户端证书和配置文件,客户端需要的一共有5个文件:ca.crt.client.crt.client.key.ta.ke ...
- VS2010下调试.NET源码
微软走向开源,是时候用vs去单步调试进入源码了.参考地址:http://blog.csdn.net/waxgourd0/article/details/6600182 可供参考的文章:https:// ...
- maven项目如何引用本地的jar包
下载该jar包到本地(如下载目录结构为:D:\Users\lu.wang\Downloads\searchservice\searchservice\jar\ttd.search.searchserv ...
- hdu2159二维费用背包
题目连接 背包九讲----二维费用背包 问题 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有一个可付出的最大值(背包容量).问怎样选择物 ...
- PHP在浏览器上跟踪调试的方法以及使用ChromePhp、FirePHP的简单介绍
之前用ThinkPHP时发现有个 trace 函数可以跟踪调试,感觉很有意思,网上搜索了下类似的东西,发现了 ChromePhp ,以前没想过这样来调试 PHP 程序,感觉非常方便,很有用. Thin ...
- 第一百一十六节,JavaScript,DOM操作样式
JavaScript,DOM操作样式 一.操作样式 CSS作为(X)HTML的辅助,可以增强页面的显示效果.但不是每个浏览器都能支持最新的CSS能力.CSS的能力和DOM级别密切相关,所以我们有必要检 ...
- Facebook 在page添加自己开发的app
最初接到的需求是,在facebook主页中嵌入一个类似这样领取游戏礼包的页面. 一开始连facebook开发者中心在哪里都不知道,在万能的搜索框里面找到static html之类的第三方应用,但是这样 ...
- cp执行命令,如何直接覆盖不提示
参数说明 -i, --interactive prompt before overwrite (overrides a previous -n option) #文件存在是,交互式提示是否覆盖 - ...
- sql第二天
--基本格式 select * from tblclass --对于列进行限制 --格式一:取指定列 select cid,cname from TblClass select cname from ...