BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声
1679: [Usaco2005 Jan]Moo Volume 牛的呼声
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 723 Solved: 346
[Submit][Status]
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
* Line 1: A single integer, the total volume of all the MOOs.
Sample Input
1
5
3
2
4
INPUT DETAILS:
There are five cows at locations 1, 5, 3, 2, and 4.
Sample Output
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.
HINT
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define inf 1000000000
#define maxn 10000+100
#define maxm 100000+100
#define ll long long
using namespace std;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
ll a[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ll n=read(),ans=,sum;
for(int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);sum=a[];
for(int i=;i<=n;i++)
{
ans+=(a[i]*(i-))-sum;sum+=a[i];
}
printf("%lld\n",*ans);
return ;
}
BZOJ1679: [Usaco2005 Jan]Moo Volume 牛的呼声的更多相关文章
- BZOJ 1679: [Usaco2005 Jan]Moo Volume 牛的呼声( )
一开始直接 O( n² ) 暴力..结果就 A 了... USACO 数据是有多弱 = = 先sort , 然后自己再YY一下就能想出来...具体看code --------------------- ...
- 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)
http://www.lydsy.com/JudgeOnline/problem.php?id=1679 水题没啥好说的..自己用笔画画就懂了 将点排序,然后每一次的点到后边点的声音距离和==(n-i ...
- bzoj 1679: [Usaco2005 Jan]Moo Volume 牛的呼声【枚举】
直接枚举两两牛之间的距离即可 #include<iostream> #include<cstdio> #include<algorithm> using names ...
- BZOJ1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 570 Solved: 310[Submi ...
- BZOJ 1677: [Usaco2005 Jan]Sumsets 求和( dp )
完全背包.. --------------------------------------------------------------------------------------- #incl ...
- BZOJ 1677: [Usaco2005 Jan]Sumsets 求和
题目 1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 617 Solved: 344[Su ...
- 1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 626 Solved: 348[Submi ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- Poj2231 Moo Volume 2017-03-11 22:58 30人阅读 评论(0) 收藏
Moo Volume Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22104 Accepted: 6692 Descr ...
随机推荐
- Change Fragment layout on orientation change
Warning: this may be a pre-Lollipop answer. A Fragment doesn't get re-inflated on configuration chan ...
- android学习笔记----JNI中的c控制java
面向对象的底层实现 java作为面向对象高级语言,可对现实世界进行建模.和面向过程不同的是面向对象软件的编写不是流程的堆积,而是对业务逻辑的多视角分解和分类.其过程大致为: 1).将知识分解 ...
- php 多维数组转换
把字符类型转换成时间类型的,先用foreach遍历出来时间,在通过时间函数转换成时间格式; 例子: <?phpecho "<pre>";$lsrfield = a ...
- mssql 创建触发器
MS-SMS里创建触发器: 首先右击表内的触发器文件夹图标 然后输入触发器创建指令,一下案例:(添加创建时间) 创建: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFI ...
- Java中View游戏开发框架
java中游戏开发引擎View比较适合被动触发的游戏,不能使用于那种对战的游戏 Game01Activity.java 这里是调用的activity package cn.sun.syspro; i ...
- HBuilder+移动APP开发实例
mui: 官网:http://dcloudio.github.io/mui/ 说明:一般要把官网内容通读一遍,这是开发的基础 开始 1.新建项目 在首页点击新建移动App,如下: 或者在项目管理器内右 ...
- 1.PhotoShop缩小图片的三种方式
先声明,本人不是高前端的,若有不当或者不合理的地方,还望前端爱好者多多指教.此处只是留作个人记录备忘. PS中有三种缩小 1.视图缩小,那方法很多缩放工具.Ctrl+"-",导航器 ...
- 02.[WPF]如何固定窗口的大小
在WPF开发过程中碰到一个需求,要求保证窗口大小不变,即便是双击 titlebar 也不能改变窗口大小和位置.要实现这样的效果,需要执行如下步骤: 1,分别设置窗口的 Width/MaxWidth/M ...
- Java GC 日志输出分析
搜到的几篇讲GC日志的文章,学到了很多东西.但是有些错误或者不够精确的地方. 因此自己尝试着总结一下. 先写个程序,然后结合程序解释每句话的意思. 运行参数 -Xms200M -Xmx200M -Xm ...
- cetos 6.3 安装 apache+mysql+php
1.安装 apache 服务器 yum install httpd 启动服务 service httpd start or /etc/init.d/httpd start 2.安装 mysql 数 ...