114. Telecasting station

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

Every city in Berland is situated on Ox axis. The government of the country decided to build new telecasting station. After many experiments Berland scientists came to a conclusion that in any city citizensdispleasure is equal to product of citizens amount in it by distance between city and TV-station. Find such point on Ox axis for station so that sum of displeasures of all cities is minimal.

Input

Input begins from line with integer positive number N (0<N<15000) – amount of cities in Berland. Following N pairs (XP) describes cities (0<X, P<50000), where X is a coordinate of city and P is an amount of citizens. All numbers separated by whitespace(s).

Output

Write the best position for TV-station with accuracy 10-5.

Sample Input

4
1 3
2 1
5 2
6 2

Sample Output

3.00000

把权值看成有多少个人,求中位数。
 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; #define maxn 15005 struct node { int x,p;
}; int n;
node s[maxn]; bool cmp(node a,node b) {
return a.x < b.x;
} int main() {
//freopen("sw.in","r",stdin); scanf("%d",&n); int sum = ;
for(int i = ; i <= n; ++i) {
scanf("%d%d",&s[i].x,&s[i].p);
sum += s[i].p;
} sort(s + ,s + n + ,cmp); int now = ;
double m1,m2;
for(int i = ; i <= n; ++i) {
now += s[i].p;
if(now >= sum / ) {
m1 = s[i].x;
if(now >= sum / + ) m2 = s[i].x;
else m2 = s[i + ].x;
break;
} } if(sum % ) printf("%.5f\n",m2);
else printf("%.5f\n",(m1 + m2) / ); return ; }

SGU 114的更多相关文章

  1. Telecasting station - SGU 114(带劝中位数)

    题目大意:在一个数轴上有N个点,每个点都有一个权值,在这个数轴上找一个点,是的每个点到这个点的距离之和乘上权值的总和最小. 分析:以前也遇到过类似的问题,不过并不知道这是带权值的中位数问题,百度百科有 ...

  2. SGU 114.Telecasting station

    题意: 百慕大的每一座城市都坐落在一维直线上.这个国家的政府决定建造一个新的广播电视台.经过了许多次试验后,百慕大的科学家们提出了一个结论,在每座城市的不满意度等于这座城市的市民数与这座城市与广播电视 ...

  3. SGU 114. Telecasting station 三分or找中位数

    题目链接点这儿 一開始想都没想...直接上了三分...结果...sample的答案不一样...可是过了...然后又看了看. . . 发现这不就是高中或者初中出过的求中位数的题么. . .直接找到这些的 ...

  4. 数学 + 带权中位数 - SGU 114 Telecasting station

    Telecasting station Problem's Link Mean: 百慕大的每一座城市都坐落在一维直线上,这个国家的政府决定建造一个新的广播电视台. 经过了许多次试验后,百慕大的科学家们 ...

  5. 今日SGU 5.5

    SGU 114 题意:求一个点到其他点的距离总和最小,距离的定义是x轴距离乘以那个点的人数p 收获:带权中位数,按坐标排序,然后扫一遍,最后权值超过或等于总权值的一半时的那个点就是答案,证明暂无 #i ...

  6. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  7. 离线 + 位优化 - SGU 108 Self-numbers 2

    SGU 108 Self-numbers 2 Problem's Link Mean: 略有这样一种数字:对于任意正整数n,定义d(n)为n加上n的各个位上的数字(d是数字的意思,Kaprekar发明 ...

  8. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  9. 编写高质量代码:改善Java程序的151个建议(第8章:异常___建议114~117)

    建议114:不要在构造函数中抛出异常 Java异常的机制有三种: Error类及其子类表示的是错误,它是不需要程序员处理也不能处理的异常,比如VirtualMachineError虚拟机错误,Thre ...

随机推荐

  1. 两对整数明明完全一样,为何一个输出true,一个输出false?&&神奇代码(StrangeIntegerBehavior.java)输出诡异的结果,原因何在

    下面有一段代码: public class Main {     public static void main(String[] args) {                   Integer ...

  2. Allegro设置十字大光标

    使用大十字光标,在摆放元器件时,容易对齐.在allegro中,可以通过设置实现大十字光标,其具体方法如下: 1.选择Setup->User Perferences,即可出现如下图所示界面: 2. ...

  3. .NET SOCKET通信编程

    1 using System; 2 using System.Net; 3 using System.Net.Sockets; 4 using System.Text; 5 6 public clas ...

  4. php中fopen函数用法详解(打开文件)

    介绍下php中的fopen函数. 1.resource  fopen(string  $filename, string $mode [,bool $use_include_path [, resou ...

  5. DBCC Check

    DBCC CHECKDB 可以完成两个任务 (1)检查数据库里有没有损坏发生 (2)尽力修复数据库损坏,是数据能重新被正常访问 DBCC 下列步骤执行下列操作 1.检查一些关键性的表 sysalocu ...

  6. CodeForces 478B 第八次比赛 B题

    Description n participants of the competition were split into m teams in some manner so that each te ...

  7. Arrays.asList方法总结

    import java.util.Arrays; import java.util.List; /** * * 本类演示了Arrays类中的asList方法 * 通过四个段落来演示,体现出了该方法的相 ...

  8. 编译linux内核问题

    1: openssl/opensslv.h: No such file or directory sudo apt-get install libssl-dev 2:一般配置内核树,需要先make o ...

  9. Nginx 老是抢先捕获了404 我想这个404我Yii项目来处理 要怎么配置?

    配置Nginx vhost的时候别指定error_page 它就不会跟Yii抢生意了 or 你弄一个frontendController   然后再里面 加上 $user->loginRequi ...

  10. Caffe安装教程(原创)

    转载请注明地址 说明:本文档参考自Caffe官网的安装说明,http://caffe.berkeleyvision.org/installation.html 如果对安装过程中,需要用到的依赖不明,请 ...