# SGU114-Telecasting station

9099人阅读 评论(0)

### 114. Telecasting station

time limit per test: 0.5 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 citizens displeasure 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


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
using namespace std;
struct N
{
double x;
int p;
} a[15009];
int b[15009];
int cmp(N a,N b)
{
return a.x<b.x;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(b,0,sizeof(b));
for(int i=0; i<n; i++)
scanf("%d%d",&a[i].x,&a[i].p);
sort(a,a+n,cmp);
int s=0;
for(int i=0; i<n; i++)
{
s+=a[i].p;
b[i]=s;
}
int mid=s/2,w;
for(int i=0; i<n; i++)
{
if(b[i]>=mid)
{
w=i;
break;
}
}
printf("%d\n",a[w].x);
}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：399364次
• 积分：6452
• 等级：
• 排名：第3905名
• 原创：240篇
• 转载：7篇
• 译文：0篇
• 评论：45条
文章分类