Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 22104 | Accepted: 6692 |
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.
————————————————————————————————————
题目的意思是给出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) 收藏的更多相关文章
- CSS_Spirte实现原理 分类: HTML+CSS 2015-04-28 22:58 531人阅读 评论(0) 收藏
CSS Spirte就是所谓的把很多的小图标合并成一张大的图片,然后使用CSS的background-position属性,来动态的定位自己需要图标的位置.这样做的目的主要是减少HTTP请求,加快网页 ...
- 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 ...
- 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 ...
- 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 ...
- UIAlertController高级之嵌入其他控件 分类: ios技术 2015-02-02 11:58 96人阅读 评论(0) 收藏
在编码过程中,我们经常遇到需要这样一个效果,就是弹出框的嵌套; 举个最简单的例子,比如你要选择时间,必然需要一个时间选择器DatePicker.但是这个选择器又是在你点击某按钮时弹出,弹出方式最常见的 ...
- 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 ...
- StatusStrip 分类: C# 2015-07-23 11:58 2人阅读 评论(0) 收藏
通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间空白显示 居右边显示时间信息 1.创建窗体及添加StatusStrip 默认StatusStrip名称 ...
- java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏
2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...
- Struts知识问答 分类: 面试 2015-07-10 22:01 4人阅读 评论(0) 收藏
1. 简述Struts框架的初始化流程. 答案: 对于采用Struts框架的Web应用,在Web应用启动时就会加载并初始化控制器ActionServlet ActionServlet从struts-c ...
随机推荐
- 几个与JVM相关的JDK工具:jps, jstat, jmap
在项目中遇到OOM(Out of Memory)的问题,为了分析内存和JVM的垃圾回收器GC问题,一并把JVM相关的一些工具也研究了一下: jps:Java进程查看工具,实际上它和Unix/Linux ...
- SQL中利用脚本创建database mail.
SQL中利用脚本创建database mail 编写人:CC阿爸 2014-6-14 多话不讲,请参考以下脚本 use
- 关于layoutparam 请铭记。。。。
//rl_pager 是RelativeLayout findViewById(R.id.rl_pager).setLayoutParams(new RelativeLayout.LayoutPara ...
- [html][javascript] 正则匹配示例
var str="akdlfaklhello 1234klfd1441ksalfd9000kals8998j2345fd;lsa"; var reg = new RegExp(/( ...
- Java ScriptEngine 解析js
Java ScriptEngine 解析js 1.脚本引擎 ① 通过脚本名称获取: ScriptEngine engine = new ScriptEngineManager().getEn ...
- HDU6128-Inverse of sum
参考这篇博客:https://blog.csdn.net/dormousenone/article/details/77340852 #include<bits/stdc++.h> usi ...
- C语言指针的一些题目
1.将从键盘输入的每个单词的第一个字母转换成大写字母输入时各单词以空格隔开,用“.”结束输入 解体思路: 把输入的字符存入字符数组中直到输入".",然后调用函数,把字符串的第一个 ...
- zmq消息订阅
一个需求,用户预约了手机超时没有使用,要通知到预约的用户“设备超时”. 我本来是自己这一端计时然后超时后推送通知的. 但是上海测说他那边计时,然后释放手机.我这边只要订阅他那边的消息就好了. 外部的应 ...
- selenium IDE测试中的坑
selenium IDE工具是firefox自带的一个网页自动化测试工具,因为它是IDE所以它很方便使用,但也因为它是IDE所以它有那么些坑. 问题:selenium回放中timeout问题 网页的打 ...
- Android工程目录结构
----------siwuxie095 首先创建一个简单的项目:MainActivity 工程目录结构一览: 工程目录结构介绍: 1.manifests目录 里面有一个AndroidManifest ...