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

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.

————————————————————————————————————

题目的意思是给出N点,,算出每个点到其他点的距离和,再求和

找到规律推出公式

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long LL a[10005]; int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
LL ans=0;
for(int i=1;i<n;i++)
{
ans+=(a[i]-a[i-1])*i*(n-i)*2;
}
printf("%lld\n",ans); } return 0;
}

跑暴力貌似也能过

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long LL a[10005]; int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
LL ans=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
ans+=(a[j]-a[i]);
}
printf("%lld\n",ans*2); } return 0;
}

Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏的更多相关文章

  1. CSS_Spirte实现原理 分类: HTML+CSS 2015-04-28 22:58 531人阅读 评论(0) 收藏

    CSS Spirte就是所谓的把很多的小图标合并成一张大的图片,然后使用CSS的background-position属性,来动态的定位自己需要图标的位置.这样做的目的主要是减少HTTP请求,加快网页 ...

  2. Hdu1695 GCD 2017-06-27 22:19 30人阅读 评论(0) 收藏

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  3. hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏

    use sentinel to avoid boudary testing, use swap trick to avoid extra copy. original version #include ...

  4. Design T-Shirt 分类: HDU 2015-06-26 11:58 7人阅读 评论(0) 收藏

    Design T-Shirt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  5. UIAlertController高级之嵌入其他控件 分类: ios技术 2015-02-02 11:58 96人阅读 评论(0) 收藏

    在编码过程中,我们经常遇到需要这样一个效果,就是弹出框的嵌套; 举个最简单的例子,比如你要选择时间,必然需要一个时间选择器DatePicker.但是这个选择器又是在你点击某按钮时弹出,弹出方式最常见的 ...

  6. Codeforces735B Urbanization 2016-12-13 11:58 114人阅读 评论(0) 收藏

    B. Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  7. StatusStrip 分类: C# 2015-07-23 11:58 2人阅读 评论(0) 收藏

    通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间空白显示 居右边显示时间信息 1.创建窗体及添加StatusStrip   默认StatusStrip名称 ...

  8. java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏

    2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...

  9. Struts知识问答 分类: 面试 2015-07-10 22:01 4人阅读 评论(0) 收藏

    1. 简述Struts框架的初始化流程. 答案: 对于采用Struts框架的Web应用,在Web应用启动时就会加载并初始化控制器ActionServlet ActionServlet从struts-c ...

随机推荐

  1. Appcan、apicloud、HBuilder 不同之处解析

    来源:http://www.mamicode.com/info-detail-1129829.html 现在Hybrid app是一中非常火热的开发模式,在国内对应的开发工具也乱象丛生,有WeX5.c ...

  2. emacs配置buffer的快捷键

    emacsConfig/buffer-setting.el (global-set-key (kbd "<M-left>") 'previous-buffer) (gl ...

  3. 黄聪:Wordpress程序Mysql查询导致CPU100%,页面错误增量飙高解决方案

    最近做的网站,访客一多,CPU就会飙到100%,找了网上很多解决方案,用了下面的方法进行优化: 1.mysql开启慢查询方法: 在my.ini的[mysqld]添加如下语句: log-slow-que ...

  4. 简化Redis数据访问代码RedisTemplate

    ---恢复内容开始--- Redis数据结构简介: Redis可以存储键与5中数据结构类型之间的映射,这5中数据结构类型分别是;String(字符串),List(列表),Set(集合),Hash(散列 ...

  5. Linux环境崩溃生成core文件以及调试

    Linux环境崩环境溃生成core文件以及调试 gdb结合coredump定位崩溃进程 Linux 使用core file文件快速定位程序崩溃代码行 http://www.cnblogs.com/ha ...

  6. PhpStorm 配置在浏览器中打开文件

    这东东中文资料太少- -鼓捣了好久才有结果 点击File-Settings-Deployment .点+按钮增加服务器 Mapping 设置工程路径等 点击 Edit Confi 这东东中文资料太少- ...

  7. Django ORM-02

    6.ForeignKey 相关操作 1.正向查找 正向查找:那么什么是正向查找,我们知道对于一对多或者多对一的情况,我们一般将ForeignKey设置在多的一边,比如我们的书籍与出版社一般是多对一的, ...

  8. J2EE Filter中修改request内容

    最近在做一个微信相关的网站,很多地方涉及到微信表情的输入,导致内容无法插入到数据库,虽然有用到一个表情过滤的工具类,但是需要过滤的地方比较多,于是想到在过滤器中过滤用户请求的内容. request这个 ...

  9. c++ new 与malloc有什么区别

    前言 几个星期前去面试C++研发的实习岗位,面试官问了个问题: new与malloc有什么区别? 这是个老生常谈的问题.当时我回答new从自由存储区上分配内存,malloc从堆上分配内存:new/de ...

  10. 跟我学算法-opencv加载,修改,保存

    #include<opencv2/opencv.hpp> #include<iostream> #include<math.h> using namespace c ...