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. 解决yum 不能更新问题 :yum 报错Loaded plugins: fastestmirror, refresh-packagekit, security

    2018-07-02       21:43:13 Yum报错 [root@db yum.repos.d]# yum makecache Loaded plugins: fastestmirror, ...

  2. scrollWidth,clientWidth,offsetWidth的区别 ---转载的

    转载自博客:http://www.cnblogs.com/kongxianghai/p/4192032.html 通过一个demo测试这三个属性的差别. 说明: scrollWidth:对象的实际内容 ...

  3. https请求失败,解决方法

    把请求头中 Content-Type 属性去掉就可以了

  4. Python基础之文件

    输出一行一行的,效率更高 一个任务: 主函数:

  5. NP、NPC、NP-hard问题的定义

    NP-hard问题    定义:NP-hard问题是这样的问题,只要其中某个问题可以在P时间内解决,那么所有的NP问题就都可以在P时间内解决了.NP-c问题就是NP-hard问题.但注意NP-hard ...

  6. 用Tensorflow搭建网络

    层 创建层 创建密集连接层,并应用激活函数 x = tf.placeholder(tf.float32, shape=[None, 3]) linear_model = tf.layers.Dense ...

  7. red ant

    Red Ant(红蚁)网络运维管理系统是IT运维管理系统,提供智能的B/S接口可视化人机界面,通过简单的操作实现全方位的网络专线.服务器.中间件.各种应 用程序.机房动力环境等监控管理,“化繁为简”, ...

  8. ES6系列_2之新的声明方式

    在ES5中我们在声明时只有一种方法,就是使用var来进行声明,ES6对声明的进行了扩展,现在可以有三种声明方式. (1)var:它是variable的简写,可以理解成变量的意思. (2)let:它在英 ...

  9. Basic64 编码解码

    import sun.misc.BASE64Decoder; public class Base64 { /** * 字符串转Base64编码 * @param s * @return */ publ ...

  10. java中回调函数的使用

    package com.huawei.common; import java.sql.ResultSet;import java.sql.SQLException; /** * 回调函数 * @aut ...