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的牛的总数和距离 ...
随机推荐
- 打开Domion 提示: 管理员ID过期
今天打开Domion 提示 管理员ID过期,什么操作都做不了,如是在网上趴了下,发现以下方法好用: 管理员ID文件被设置为允许超期,同时又没有其他ID文件可以用于访问服务器.如果尝试用已经超期的管理员 ...
- 数据库分库分表(sharding)
地址: http://blog.csdn.net/column/details/sharding.html
- ubuntu使用mailx利用SMTP发送邮件
转载:http://www.blogjava.net/jasmine214--love/archive/2010/10/09/334102.htmlLinux下mail利用外部邮箱发送邮件的方法: 1 ...
- main函数中argc理解
其实: int main(int argc,char *argv[])是UNIX和Linux中的标准写法,而int main()只是UNIX及Linux默许的用法..void main(int arg ...
- [转载] 深入 superviser
模块简介 新人接触线上的时候一般都会碰到supervise这个工具,导师对这个模块的解释一般就是,这个模块是监控进程,当进程挂掉之后,supervise会将进程启动.这样当进程出 现问题,如因出cor ...
- placeholder在不同浏览器下的表现及兼容方法(转)
1.什么是placeholder? placeholder是html5新增的一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点(或 ...
- python使用open经常报错:TypeError: an integer is required的解决方案
错误是由于从os模块引入了所有的函数导致的,os模块下有一个open函数,接受整型的文件描述符和打开模式,from os import *引入os模块的open函数,覆盖了python内建的open函 ...
- Java可变参数 & Python可变参数 & Scala可变参数
Java 可变参数的特点: (1).只能出现在参数列表的最后: (2)....位于变量类型和变量名之间,前后有无空格都可以: (3).调用可变参数的方法时,编译器为该可变参数隐含创建一个数组,在方法体 ...
- iOS 开发之照片框架详解(2)
一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...
- Sqlserver_sql注入
随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多.但是由于这个行业的入门门槛不高,程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据的合法性进 ...