SGU 114 Telecasting station
来源:互联网 发布:淘宝导航条装修 编辑:程序博客网 时间:2024/05/16 12:07
题意:n个城市,第i个城市坐标为x[i],人口为p[i],现在要建立一个电视台,使得各个城市到电视台的距离乘以该城市人口之和最小。
分析:单纯的带权中位数问题。百度百科上有相关证明。
可以这样来简单考虑:若各个城市人口均为1,则问题就是求城市坐标的中位数。现在人口为p,则可以看做是有p个人口为1的城市,这样就把问题转化为求中位数。
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<map>#include<algorithm>using namespace std;#define LL long longstruct city{ double x,p;}c[50005];bool cmp(city a,city b){ return a.x<=b.x;}int main(){ int n; scanf("%d",&n); double sum=0.0; for(int i=0;i<n;++i) { scanf("%lf%lf",&c[i].x,&c[i].p); sum+=c[i].p; } double s=0.0; sort(c,c+n,cmp); for(int i=0;i<n;++i) { s+=c[i].p; if(s-sum/2>=1e-10) {printf("%.10lf\n",c[i].x);break;} } return 0;}
0 0
- sgu 114 Telecasting station
- Sgu 114 Telecasting station
- SGU 114 Telecasting station
- SGU 114 Telecasting station
- SGU 114 Telecasting station
- SGU 114 Telecasting station 单峰极值函数
- SGU 114 Telecasting station(水~)
- SGU 114 Telecasting station(二分)
- [SGU]114. Telecasting station
- [sgu]Telecasting station【三分】
- 【SGU】 114. Telecasting station 中位数
- SGU 114. Telecasting station 三分or找中位数
- SGU114 Telecasting station 三分
- SGU114-Telecasting station
- sgu114 Telecasting station 三分
- sgu114:Telecasting station
- 114. Telecasting station
- SGI114 Telecasting station
- 程序猿:我的未来,在哪里?
- 现代科技论文的必要附加部分
- 527A. Playing with Paper
- MySQL数据库操作(二)
- Linux的五个查找命令:find,locate,whereis,which,type
- SGU 114 Telecasting station
- poj 3709 K-Anonymous Sequence dp斜率优化
- 关于ios极光推送server端注意的地方
- oracle中存储过程
- 第三周项目五(2):数组做数据成员(输入工资和员工人数)
- /bin、/sbin、/usr/bin、/usr/sbin目录的区别
- 第3周课后实践·阅读程序(2)-利用指针访问私有数据成员
- 每个程序员都应该了解的 CPU 高速缓存
- 关于Java 中几种不同的引用jar文件的方法