SGU 114
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 (X, P) 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的更多相关文章
- Telecasting station - SGU 114(带劝中位数)
题目大意:在一个数轴上有N个点,每个点都有一个权值,在这个数轴上找一个点,是的每个点到这个点的距离之和乘上权值的总和最小. 分析:以前也遇到过类似的问题,不过并不知道这是带权值的中位数问题,百度百科有 ...
- SGU 114.Telecasting station
题意: 百慕大的每一座城市都坐落在一维直线上.这个国家的政府决定建造一个新的广播电视台.经过了许多次试验后,百慕大的科学家们提出了一个结论,在每座城市的不满意度等于这座城市的市民数与这座城市与广播电视 ...
- SGU 114. Telecasting station 三分or找中位数
题目链接点这儿 一開始想都没想...直接上了三分...结果...sample的答案不一样...可是过了...然后又看了看. . . 发现这不就是高中或者初中出过的求中位数的题么. . .直接找到这些的 ...
- 数学 + 带权中位数 - SGU 114 Telecasting station
Telecasting station Problem's Link Mean: 百慕大的每一座城市都坐落在一维直线上,这个国家的政府决定建造一个新的广播电视台. 经过了许多次试验后,百慕大的科学家们 ...
- 今日SGU 5.5
SGU 114 题意:求一个点到其他点的距离总和最小,距离的定义是x轴距离乘以那个点的人数p 收获:带权中位数,按坐标排序,然后扫一遍,最后权值超过或等于总权值的一半时的那个点就是答案,证明暂无 #i ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- 离线 + 位优化 - SGU 108 Self-numbers 2
SGU 108 Self-numbers 2 Problem's Link Mean: 略有这样一种数字:对于任意正整数n,定义d(n)为n加上n的各个位上的数字(d是数字的意思,Kaprekar发明 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- 编写高质量代码:改善Java程序的151个建议(第8章:异常___建议114~117)
建议114:不要在构造函数中抛出异常 Java异常的机制有三种: Error类及其子类表示的是错误,它是不需要程序员处理也不能处理的异常,比如VirtualMachineError虚拟机错误,Thre ...
随机推荐
- git使用小结
本篇文章主要介绍自己在平时工作中使用git的一些常用命令,之前都是记录在本子上面,现在把他们记录在博客上,便于保存和回顾. 1. 建立自己的git仓库 1.1 在一个新建的repo文件夹里面,执行gi ...
- iOS ARC下循环引用的问题 -举例说明strong和weak的区别
strong:适用于OC对象,作用和非ARC中的retain作用相同,它修饰的成员变量为强指针类型weak:适用于OC对象,作用和非ARC中的assign作用相同,修饰的成员变量为弱指针类型assig ...
- ●linux进程的查看与操作●
查看进程:ps -le | more ,ps -aux | more ,ps & 后台运行 jobs 查看后台进程 fg [n]调到前台 bg放到后台 ctrl +c 终止 ctrl ...
- ADO.NET笔记——使用DataAdapter执行增删改操作
相关知识: DataSet中的数据一旦从数据库下载下来,便不再与数据库保持联系.如果修改了DataSet中的数据,需要重新建立连接,并且通过SQL命令将修改更新到数据库去 编写SQL命令往往比较繁琐和 ...
- jquery循环table中tbody的tr中input:text,将值进行拼接传入控制器并返回状态和描述
引用jquery $(function(){ $("#按钮id").click(function(){ var nums="";//变量 $("#ta ...
- ajax对一些没有接口的数据进行分析和添加方法
对于一些没有接口的数据进行分析和添加方法: <script src="ajax.js"><script>//插入ajax文件 <script> ...
- ios 控件
反序列化 JSONModel 上拉刷新 下拉加载更多 MJRefresh AFNetworking 2.5 Asynchronous image downloader with cache - SDW ...
- rinetd 安装使用
1 下载解压: wget http://www.boutell.com/rinetd/http/rinetd.tar.gz tar zxvf rinetd.tar.gz 2 手动建立目录 mkdir ...
- 一款jquery编写图文下拉二级导航菜单特效
一款jquery编写图文下拉二级导航菜单特效,效果非常简洁大气,很不错的一款jquery导航菜单特效. 这款jquery特效适用于很多的个人和门户网站. 适用浏览器:IE8.360.FireFox.C ...
- How to changes to Table & EDT Relations[AX2012]
Well I hope everyone is having a fine week so far. Oh Wednesdays, the furthermost point between two ...