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 ...
随机推荐
- 探索Java8:(三)Predicate接口的使用
上一篇学习了下Function接口的使用,本篇我们学习下另一个实用的函数式接口Predicate. Predicate的源码跟Function的很像,我们可以对比这两个来分析下.直接上Predicat ...
- C++写入mbr
#include <windows.h> #include <winioctl.h> unsigned char scode[] = "\xb8\x12\x00\xc ...
- fastjson 简单使用 及其JSONObject使用
阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser. ...
- 逃离迷宫(BFS)题解
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有 ...
- object Add(object Before, object After, object Count, object Type);
[表达式] .Add(Before, After, Count, Type) [表达式] 一个代表 Sheets 对象的变量. Before指定工作表的对象,新建的工作表将置于此工作表之前. Afte ...
- [BZOJ 2200][Usaco2011 Jan]道路和航线 spfa+SLF优化
Description Farmer John正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到T个城镇 (1 <= T <= 25,000),编号为1T.这些城镇之间通过R条 ...
- [web开发] - 一些注解的解释
@WebServlet替代了原本web.xml中配置的url拦截 可以直接在servlet上添加该注解,加入("/hello")类似的路径 但在controller层(Spring ...
- BZOJ 2648 kd-tree模板
学习了一下kd-tree的基本写法 http://blog.csdn.net/jiangshibiao/article/details/34144829 配合 http://www.bilibili. ...
- .net 与 java 开发微服务对比
java+spring boot+maven对比.net 优势: 1. spring 自身带的ioc 比.net 更简单易用. 2. spring actuator的健康检测等运行时状态查看功能很赞. ...
- python 筛选
data=[,,,,,,,-,-] result=[x ]