I-MooFest(POJ 1990)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 5697 | Accepted: 2481 |
Description
Each cow i has an associated "hearing" threshold v(i) (in the range 1..20,000). If a cow moos to cow i, she must use a volume of at least v(i) times the distance between the two cows in order to be heard by cow i. If two cows i and j wish to converse, they must speak at a volume level equal to the distance between them times max(v(i),v(j)).
Suppose each of the N cows is standing in a straight line (each cow at some unique x coordinate in the range 1..20,000), and every pair of cows is carrying on a conversation using the smallest possible volume.
Compute the sum of all the volumes produced by all N(N-1)/2 pairs of mooing cows.
Input
* Lines 2..N+1: Two integers: the volume threshold and x coordinate for a cow. Line 2 represents the first cow; line 3 represents the second cow; and so on. No two cows will stand at the same location.
Output
Sample Input
4
3 1
2 5
2 6
4 3
Sample Output
57
Source
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 20005 struct P{
ll v, p;
bool operator < (const P& t) const {
return t.v > v;
}
}cow[MAXN];
ll c_ount[MAXN] = {};
ll total[MAXN] = {};
ll sum_tot[MAXN] = {};
int n; ll lowbit(ll x)
{
return x & (-x);
} void add(int x, int d, ll c[])
{
while(x < MAXN) {
c[x] += d;
x += lowbit(x);
}
} ll Sum(ll x, ll c[])
{
ll ret = ;
while(x > )
{
ret += c[x];
x -= lowbit(x);
}
return ret;
} int main()
{
scanf("%d", &n);
repu(i, , n + ) scanf("%lld%lld", &cow[i].v, &cow[i].p);
sort(cow + , cow + n + );
repu(i, , n + ) sum_tot[i] = sum_tot[i - ] + cow[i].p;
ll sum = , num_cow = , sum_total = ;
add(cow[].p, , c_ount);
add(cow[].p, cow[].p, total);
repu(i, , n + ) {
num_cow = Sum(cow[i].p, c_ount);
sum_total = Sum(cow[i].p, total);
sum += cow[i].v * (num_cow * cow[i].p - sum_total
+ (sum_tot[i - ] - sum_total - (i - - num_cow) * cow[i].p));
add(cow[i].p, , c_ount);
add(cow[i].p, cow[i].p, total);
}
printf("%lld\n", sum);
return ;
}
I-MooFest(POJ 1990)的更多相关文章
- MooFest POJ - 1990 (树状数组)
Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a social gather ...
- ●POJ 1990 MooFest
题链: http://poj.org/problem?id=1990 题解: 树状数组 把牛们按x坐标从小到大排序,依次考虑每头牛对左边和对右边的贡献. 对左边的贡献:从左向右枚举牛,计算以当前牛的声 ...
- POJ 1990 MooFest(zkw线段树)
[题目链接] http://poj.org/problem?id=1990 [题目大意] 给出每头奶牛的位置和至少要多少分贝的音量才能听到谈话 现在求奶牛两两交流成功需要的分贝*距离的总和. [题解] ...
- POJ 1990 MooFest(树状数组)
MooFest Time Limit: 1000MS Mem ...
- POJ 1990 MooFest --树状数组
题意:牛的听力为v,两头牛i,j之间交流,需要max(v[i],v[j])*dist(i,j)的音量.求所有两两头牛交谈时音量总和∑(max(v[i],v[j])*abs(x[j]-x[i])) ,x ...
- poj 1990 MooFest
题目大意: FJ有n头牛,排列成一条直线(不会在同一个点),给出每头牛在直线上的坐标x.另外,每头牛还有一个自己的声调v,如果两头牛(i和j)之间想要沟通的话,它们必须用同个音调max(v[i],v[ ...
- POJ 1990:MooFest(树状数组)
题目大意:有n头牛,第i头牛声调为v[i],坐标为x[i],任意两值牛i,j沟通所需的花费为abs(x[i]-x[j])*max(v[i],v[j]),求所有牛两两沟通的花费. 分析: 我们将奶牛按声 ...
- POJ 1990 MooFest【 树状数组 】
题意:给出n头牛,每头牛有一个听力v,坐标x,两头牛之间的能量为max(v1,v2)*dist(v1,v2),求总的能量值 先将每头牛按照v排序,排完顺序之后,会发现有坐标比当前的x小的,会有坐标比当 ...
- poj 1990
题目链接 借鉴cxlove大神的思路 题意:听力v,位置x,2个牛交流声音为max(v1,v2)*(x1-x2),求总的 10000^2 tle 用的树状数组做的,排序,2个,小于vi的牛的总数和距离 ...
随机推荐
- 用jq移除某一个特定样式
用JQ移除样式中的某条单独的样式,实际移除不了的,只能将其赋值为空$(function(){ $(".tableStyle").css("background-color ...
- “System.Data.OracleClient.OracleConnection”已过时
处理办法: 在oracle 安装目录下 找到 Oracle.DataAccess.dll添加引用,然后 using Oracle.DataAccess.Client;其他的都不用动,即可.连接字符串中 ...
- bzoj 1202: [HNOI2005]狡猾的商人 并查集好题
1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2946 Solved: 1384[Submit][Sta ...
- JMS【四】--Spring和ActiveMQ整合的完整实例
第一篇博文JMS[一]--JMS基本概念,我们介绍了JMS的两种消息模型:点对点和发布订阅模型,以及消息被消费的两个方式:同步和异步,JMS编程模型的对象,最后说了JMS的优点. 第二篇博文JMS[二 ...
- jsp get方式请求参数中包含中文乱码问题解决
1. 自己接收到参数之后在后台进行转码处理 2: 修改tomcat的配置文件 server.xml <Connector port="8080" protocol=&quo ...
- java乱码问题(转)
参考: http://blog.csdn.net/beijiguangyong/article/details/7414247 http://www.zhihu.com/question/202126 ...
- 不含类解决最后一个li边距问题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 顾维灏谈百度地图数据采集:POI自动处理率达90%
顾维灏谈百度地图数据采集:POI自动处理率达90% 发布时间:2015-12-21 22:37 来源:cnsoftnews.com 作者: 百度地图还创新研发高精地 ...
- Java 日期往后推迟n天
在Java中经常会遇到,以指定的日期为基准,计算向后n天<n可以为正.负数,负数为向前移>. 这时需要在Date类的基础上使用Calendar类,处理方法基本如下: import java ...
- HDU5886 Tower Defence 【两遍树形dp】【最长链预处理】
题意:N个点的一棵带权树.切掉某条边的价值为切后两树直径中的最大值.求各个边切掉后的价值和(共N-1项). 解法一: 强行两遍dp,思路繁琐,维护东西较多: dis表示以i为根的子树的直径,dis2表 ...