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. Codevs 1105 过河

     时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond  题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有 ...

  2. ADO.NET笔记——存储二进制大对象(BLOB)

    相关知识 上传二进制大对象(Binary Large Object)(如图片.视频等)的基本编程步骤是: 在数据库中使用varbinary(MAX).varchar(MAX)或者nvarchar(MA ...

  3. html关于强制显示 隐藏浏览器的滚动条

    浏览器的滚动条在一些特殊的展示中,是不需要的,所以必须把它隐藏掉,文章主要介绍一些隐藏或者显示IE的水平或者垂直滚动条的实现代码,需要了解的朋友可以参考下: 相关css代码如下: //强制显示滚动条: ...

  4. 【Qt】Qt之启动外部程序【转】

    简述 QProcess可以用来启动外部程序,并与它们交互. 要启动一个进程,通过调用start()来进行,参数包含程序的名称和命令行参数,参数作为一个QStringList的单个字符串. 另外,也可以 ...

  5. git记住用户名密码

    git config --global credential.helper store

  6. 用cookie实现localstorage功能

    在项目中需要利用到html5的localstorage.但在利用这个属性的时候却发现无法达到预定目标.经过不断的检查及排除,最后发现原因所在: 项目中使用的浏览器是支持localstorage的,但是 ...

  7. c#中的类型转换

    Parse类型转换 Parse()函数 int.double都能调用Parse()函数,Parse(string str);如果转换成功就成功,失败就会抛出一个异常; TryParse()函数 相应地 ...

  8. java实现mysql数据库的备份及还原

    备份: public static void backup() { try { Runtime rt = Runtime.getRuntime(); // 调用 调用mysql的安装目录的命令 Pro ...

  9. 【转载】MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry

    原文地址:MySQL 5.6主从Slave_IO_Running:Connecting/error connecting to master *- retry 作者:忆雨林枫 刚配置的MySQL主从, ...

  10. Linux /dev 自动创建设备节点

    #include <linux/module.h> #include <linux/module.h> #include <linux/kernel.h> #inc ...