SGU 114 Telecasting station(水~)
来源:互联网 发布:知秋孩子去世了 编辑:程序博客网 时间:2024/05/21 17:13
Description
给出一些点对(xi,pi)表示在x轴上xi坐标处有pi个人,现在要在x轴上找一点x0,使得sum(pi*|xi-x0|)最小
Input
第一行一整数n表示点对数,之后n行每行两个整数xi和pi
(1< n< 15000,0< xi, pi< 50000)
Output
输出使得sum(pi*|xi-x0|)最小的x0
Sample Input
4
1 3
2 1
5 2
6 2
Sample Output
3.00000
Solution
水题,找中位数
Code
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define maxn 22222struct node{ int x,p;}a[maxn];int n;int cmp(node a,node b){ return a.x<b.x;}int main(){ while(~scanf("%d",&n)) { int sum=0,temp=0; for(int i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].p); sum+=a[i].p; } sort(a,a+n,cmp); for(int i=0;i<n;i++) { temp+=a[i].p; if(temp>=sum/2) { printf("%d.00000\n",a[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
- CSS3.0使用@font-face自定义字体
- StringUtils的isBlank与isEmply
- Spring中Bean的命名 (id 和name)
- ACM-2006
- 汇编语言学习-Dos下的调试工具debug的使用教程
- SGU 114 Telecasting station(水~)
- databinding 程序包 xxx.xxx.databinding.xxxBinding 不存在
- 第三方SDK:百度地图SDK的使用
- Light OJ 1299 Fantasy Cricket (DP)
- ftp 递归下载文件 下载过了就不在下载了
- monkey 测试 adb shell monkey
- Spring-bean作用域scope详解
- java的动态代理机制详解 | Java基础
- HTML&CSS——选择器中间加空格和逗号的区别?