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 ...
随机推荐
- Win32程序支持命令行参数的做法(转载)
转载:http://www.cnblogs.com/lanzhi/p/6470406.html 转载:http://blog.csdn.net/kelsel/article/details/52759 ...
- C# MD5一句话加密
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")
- mysql 对比两个表的一致性
-- A和B两个表 数据是否一致select 自定义 from A left join B on A.id = B.id where B.id is null 注释:这样查询的结果是A表中有而B表中没 ...
- Ubuntu14.04(server amd 64)编译安装 ceres-solver
文档地址:http://www.ceres-solver.org/installation.html git地址:(需要FQ下载) git clone https://ceres-solver.goo ...
- Springboot mybatis generate 自动生成实体类和Mapper
https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...
- Python day5_tuple元祖的常见方法1_笔记
# 初识元祖# 1.元祖的一级元素不能被修改,增加,删除,但可以查看,del tu[0]错的# 2.元祖最后一个元素后注意加‘,’,并没有区别,只是为了和方法中元素区别开li=[11,22,33,44 ...
- Codeforces 911E - Stack Sorting
911E - Stack Sorting 思路: 用栈来模拟,能pop就pop,记下一个需要pop的数为temp,那么如果栈非空,栈顶肯定大于temp,那么加入栈 栈顶值-1 到 temp 的值,否则 ...
- LeetCode--021--合并两个有序链表
问题描述: 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两个链表的所有节点组成的. 示例: 输入:1->2->4, 1->3->4 输出:1->1- ...
- Yet Another Ball Problem CodeForces - 1118E (简单构造)
大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...
- 『PyTorch』第十弹_循环神经网络
RNN基础: 『cs231n』作业3问题1选讲_通过代码理解RNN&图像标注训练 TensorFlow RNN: 『TensotFlow』基础RNN网络分类问题 『TensotFlow』基础R ...