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 ...
随机推荐
- 我的第一个C语言程序 (A+B Problem)(cheney-yang)
第一个接触的C语言程序,是一个简单的A+B问题! 题目出处:http://acm.nyist.net/JudgeOnline/problem.php?pid=1 题目描述: 计算a+b的值 输入: ...
- HDFS的Java客户端操作代码(查看HDFS下所有的文件存储位置信息)
1.查看HDFS下所有的文件存储位置信息 package Hdfs; import java.net.URI; import org.apache.hadoop.conf.Configuration; ...
- C# GridView点击某列打开新浏览器窗口
C# GridView点击某列打开新窗口的方式: (1)打开浏览器新窗口:蓝色部分 通过超链接. (2)打开模式化窗口:通过OnRowCommand事件,弹出模式化窗口. 具体如下: <asp: ...
- O2O的理解
O2O 就是把线上和线下的优势完美结合,网上优惠价格,线下享受贴身服务!O2O 还可以实现不同商家的联盟 两年前的微博营销,现在没落了,那么微信营销呢,只能说来的太快了.线上来筛选服务和产品,所有的交 ...
- order by
- maven 依赖冲突的问题
如果原始系统的jarA依赖jarB1.0 而新引入的jarC依赖jarB2.0 导致系统启动报错,提示冲突,这时为了保证原始系统的稳定性, 在pom.xml文件中引入jarC时,需要exclude掉j ...
- 遍历id,根据id作为条件循环查询。
string id = "OE09924008161405102,OE36765709071405102,OE87852044171405102,OE09924008161405102&qu ...
- Adb工具常用操作-转(二)
一. PC与模拟器或真机交换文件(adb pull和adb push) 在开发阶段或其他原因,经常需要将PC上的文件复制到模拟器或真机上,或将模拟机和真机上的文件复制到PC上.使用adb pull和a ...
- Openblas编译Android NDK库的步骤
1.配置Android NDK编译工具.以下下载地址,直接放到浏览器中下载,不需要VPNlinux 32 bithttp://dl.google.com/android/ndk/android-ndk ...
- CentOS 6.5下搭建NFS文件服务器
环境介绍:服务器: 192.168.0.1客户机: 192.168.0.2安装软件包:服务器和客户机都要安装nfs 和 rpcbind 软件包:yum -y install nfs-utils rpc ...