sgu114. Telecasting station 难度:1
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 思路:转化成pi个位置为xi的城市则很好求解,此时在中点
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double inf=1e18;
const double eps=1e-9;
const int maxn=15005;
typedef pair<int ,int >P;
int n;
P x[maxn];
int main(){
scanf("%d",&n);
int sum=0;
for(int i=0;i<n;i++){
scanf("%d%d",&x[i].first,&x[i].second);
sum+=x[i].second;
}
sort(x,x+n);
int tot=0;
int ans=x[n-1].first;
for(int i=0;i<n;i++){
tot+=x[i].second;
if(tot>=(sum+1)/2){ans=x[i].first;break;}
}
printf("%d.00000\n",ans);
return 0;
}
sgu114. Telecasting station 难度:1的更多相关文章
- 数学 + 带权中位数 - SGU 114 Telecasting station
Telecasting station Problem's Link Mean: 百慕大的每一座城市都坐落在一维直线上,这个国家的政府决定建造一个新的广播电视台. 经过了许多次试验后,百慕大的科学家们 ...
- Telecasting station - SGU 114(带劝中位数)
题目大意:在一个数轴上有N个点,每个点都有一个权值,在这个数轴上找一个点,是的每个点到这个点的距离之和乘上权值的总和最小. 分析:以前也遇到过类似的问题,不过并不知道这是带权值的中位数问题,百度百科有 ...
- SGU 114.Telecasting station
题意: 百慕大的每一座城市都坐落在一维直线上.这个国家的政府决定建造一个新的广播电视台.经过了许多次试验后,百慕大的科学家们提出了一个结论,在每座城市的不满意度等于这座城市的市民数与这座城市与广播电视 ...
- SGU 114. Telecasting station 三分or找中位数
题目链接点这儿 一開始想都没想...直接上了三分...结果...sample的答案不一样...可是过了...然后又看了看. . . 发现这不就是高中或者初中出过的求中位数的题么. . .直接找到这些的 ...
- SGU114-Telecasting station
114. Telecasting station time limit per test: 0.5 sec. memory limit per test: 4096 KB Every city in ...
- SGU 114
114. Telecasting station time limit per test: 0.25 sec. memory limit per test: 4096 KB Every city in ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- [LeetCode] Gas Station 加油站问题
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
随机推荐
- Autotools使用流程【转】
本文转载自:http://blog.csdn.net/scucj/article/details/6079052 手工写Makefile是一件很有趣的事情,对于比较大型的项目,如果有工具可以代劳,自然 ...
- 在ubuntu16.04上搭建视频服务器
推荐方案三:超级简单 方案一.hls (缺陷:需要花很多时间切片) 1.Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release ...
- zedgraph右键菜单的汉化
http://blog.csdn.net/jeryler/article/details/7876376 修改 zedGraphControl的ContextMenuBuilder事件即可! zedG ...
- 04_Flume多节点load_balance实践
1.负载均衡场景 1)初始:上游Agent通过round_robin selector, 将event轮流发送给下游Collecotor1, Collector2 2)故障: 关闭Collector1 ...
- HDU 5936 Difference(折半搜索(中途相遇法))
http://acm.hdu.edu.cn/showproblem.php?pid=5936 题意: 定义了这样一种算法,现在给出x和k的值,问有多少个y是符合条件的. 思路: y最多只有10位,再多 ...
- 基于R进行相关性分析--转载
https://www.cnblogs.com/fanling999/p/5857122.html 一.相关性矩阵计算: [1] 加载数据: >data = read.csv("231 ...
- Codeforces Beta Round #95 (Div. 2) C. The World is a Theatre 组合数学
C. The World is a Theatre There are n boys and m girls attending a theatre club. To set a play " ...
- Java语言编写MD5加密方法,Jmeter如何给字符串MD5加密
package md5package; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; ...
- 《剑指offer》第四十题(最小的k个数)
// 面试题40:最小的k个数 // 题目:输入n个整数,找出其中最小的k个数.例如输入4.5.1.6.2.7.3.8 // 这8个数字,则最小的4个数字是1.2.3.4. #include < ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...