Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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.

Input

* Line 1: N

* 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

5
1
5
3
2
4

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.

 
暴力做的,之前没给牛排序,超时;按位置排序之后就过了
#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的更多相关文章

  1. Poj 2232 Moo Volume(排序)

    题目链接:http://poj.org/problem?id=2231 思路分析:先排序,再推导计算公式. 代码如下: #include <iostream> #include <a ...

  2. BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声

    1679: [Usaco2005 Jan]Moo Volume 牛的呼声 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 723  Solved: 346[ ...

  3. POJ 2010 Moo University - Financial Aid( 优先队列+二分查找)

    POJ 2010 Moo University - Financial Aid 题目大意,从C头申请读书的牛中选出N头,这N头牛的需要的额外学费之和不能超过F,并且要使得这N头牛的中位数最大.若不存在 ...

  4. BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )

    一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...

  5. Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏

    Moo Volume Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22104   Accepted: 6692 Descr ...

  6. Moo Volume POJ - 2231

    Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are ...

  7. poj -2010 Moo University - Financial Aid (优先队列)

    http://poj.org/problem?id=2010 "Moo U"大学有一种非常严格的入学考试(CSAT) ,每头小牛都会有一个得分.然而,"Moo U&quo ...

  8. B - Moo Volume

    Farmer John has received a noise complaint from his neighbor, Farmer Bob, stating that his cows are ...

  9. 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...

随机推荐

  1. openstack私有云布署实践【7.1 keystone + memcache (科兴环境)】

    其实登录数据库集群中任意1台都可以创建库,它们会实时自动同步数据库和对应的数据库权限.   首先登录kxcontroller1创建kx_keystone数据库,并赋于远程和本地访问的权限.   mys ...

  2. oracle登录时shared memory realm does not exist的解决方法

    解决办法:1.用CMD进入命令行2.sqlplus /nolog 3.conn / as sysdba4.startup   然后用sqlplus进入命令  

  3. Winsock - 1 - Winsock API

    Winsock Winsock API Winsock是网络编程接口,而不是协议. 网络原理和协议 建立Winsock规范的主要目的是提供一个与协议无关的传送接口. Winsock将网络编程接口与具体 ...

  4. Qt 打开指定的文件

    最近项目用到使用本地的office打开指定的文件,记录一下代码: QString fileName = QFileDialog::getOpenFileName(this, tr("Open ...

  5. canvas画扇形图(本文来自于http://jo2.org/html5-canvas-sector/)

    1.定义画扇形的构造函数: //扇形CanvasRenderingContext2D.prototype.sector = function (x, y, radius, sDeg, eDeg) {/ ...

  6. centos6.5 安装zabbix

    实验说明: 操作系统: CentOS6.5 64位 Web环境: Apache Mysql PHP zabbix版本: LTS 2.2.10 Linux服务器IP: 10.0.0.2 Linux客户端 ...

  7. hdu1028

    #include<stdio.h>#include<string.h>const int MAXN=130;int dp[MAXN][MAXN];//dp[i][j]表示 i ...

  8. Linux软件安装管理 - CentOS

    ---恢复内容开始--- 1. 软件包管理简介 1.1 源码包 - 脚本安装包 1.2 二进制包(RPM包,系统默认包) - 依赖性 2. rpm命令管理(Redhat Package Manager ...

  9. 利用Runtime给UITextView添加占位符(新方法)

     以前一直使用自定义UITextView通过通知中心来自定义placeHolder,最近看到这个方法,感觉更好 UITextView *textView = [[UITextView alloc]in ...

  10. [Poi2015]

    [POI2015]Łasuchy 一看以为是sb题 简单来说就是每个人获得热量要尽量多 不能找别人 首先这道题好像我自己找不到NIE的情况 很容易想到一个优化 如果一个数/2>另一个数 那么一定 ...