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 ...
随机推荐
- const T & 的适用范围
我们往往在类中的函数体,重载操作中看到 const T & 的影子,以前还是比较纳闷. 对于非内部数据类型的参数而言,象void Func(A a) 这样声明的函数注定效率比较底.因为函数体内 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- 调用WebAPI接口地址返回序列化的JSON对象中的属性都加了个k__BackingField关键字的解决办法
1.问题现象: 2.造成此问题的原因是返回的结果对象实体上面加了个可序列号特效 [Serializable].去掉就可以了. 3.解决后的效果:
- bzoj 4069~4071 APIO2015
T1 从高到底按位确定答案 A=1时f[i]表示前i个数合法的划分至少需要分出几段,时间复杂度$O(n^2log(ans))$ A>1时f[i][j]表示前i个数划分为j段是否可能合法,转移显然 ...
- springMvc上传文件、读取zip/rar文件
参考文章: http://www.cnblogs.com/interdrp/p/6734033.html 方法一: 1)没有配置org.springframework.web.multipart.co ...
- Java 将字符串转换为字符数组 toCharArray()
Java 手册 toCharArray public char[] toCharArray() 将此字符串转换为一个新的字符数组. 返回: 一个新分配的字符数组,它的长度是此字符串的长度,它的内容被初 ...
- Axure RP Extension for Chrome经常损坏
昨天自己修改后的谷歌浏览器插件,才使用了一天,今天刚打开浏览器就弹出了“已停用不支持的扩展程序”提示,第三方扩展程序就这么不受谷歌浏览器待见呢!?好吧,想办法解决! 通过扩展程序里“该扩展程序未列在 ...
- docker-ubuntu镜像,nginx镜像
docker 是将程序与机器隔开,使程序不受环境影响. 安装 sudo apt-get install docker.io ## 好用的一些命令 1.停用全部运行中的容器: docker stop $ ...
- call apply 使用
1.call 跟 apply的主要区别: call传入参数是一个一个传入,而 apply 使用的是数组传入 call(obj,arg1,arg2,arg3,arg4) apply(obj,[arg1, ...
- BDE 升级到FireDAC
BDE Query Replace Str in files by cnpack tools TQueryTFDQuery dmdb->qrypub->Open(sql); fdme ...