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


题意是说,有个国家的城市之间要建个公交(我英语不好、翻译可能会跑偏、也可能是电视塔、也可能是别的、我也不知道是啥),然后有一个不满意度,咱们自己想想也知道,肯定都喜欢把地铁站设在自己家门口。然后这个不满意度=城市的人数*这个站的位置。。。然后的然后、我也不会做这个题,直接上理论:数学家说,这是一个带权中位数问题,具体内容见 http://baike.baidu.com/link?url=NZbFTsJCCn_jsx8W24aLu6XGEVdpDH0hpO_SIzeCF7vFi_Nz-xV4pe7tzuJBpQsQSzoa719FmHYb3lr7QKV3q_   这个讲的很明白了。然后,下面的代码就自然手到擒来了!!!

#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;
}

SGU114-Telecasting station的更多相关文章

  1. sgu114. Telecasting station 难度:1

    114. Telecasting station time limit per test: 0.25 sec. memory limit per test: 4096 KB Every city in ...

  2. 数学 + 带权中位数 - SGU 114 Telecasting station

    Telecasting station Problem's Link Mean: 百慕大的每一座城市都坐落在一维直线上,这个国家的政府决定建造一个新的广播电视台. 经过了许多次试验后,百慕大的科学家们 ...

  3. Telecasting station - SGU 114(带劝中位数)

    题目大意:在一个数轴上有N个点,每个点都有一个权值,在这个数轴上找一个点,是的每个点到这个点的距离之和乘上权值的总和最小. 分析:以前也遇到过类似的问题,不过并不知道这是带权值的中位数问题,百度百科有 ...

  4. SGU 114.Telecasting station

    题意: 百慕大的每一座城市都坐落在一维直线上.这个国家的政府决定建造一个新的广播电视台.经过了许多次试验后,百慕大的科学家们提出了一个结论,在每座城市的不满意度等于这座城市的市民数与这座城市与广播电视 ...

  5. SGU 114. Telecasting station 三分or找中位数

    题目链接点这儿 一開始想都没想...直接上了三分...结果...sample的答案不一样...可是过了...然后又看了看. . . 发现这不就是高中或者初中出过的求中位数的题么. . .直接找到这些的 ...

  6. SGU 114

    114. Telecasting station time limit per test: 0.25 sec. memory limit per test: 4096 KB Every city in ...

  7. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

  8. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  9. [LeetCode] Gas Station 加油站问题

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

随机推荐

  1. 兼容性问题( css)

    记录平时遇见的兼容性问题,有更好的解决办法希望各位提出,会持续更新 提出时间 问题描述 解决方案 2014/7/15 table下面使用img或者其他元素例如embed会产生,对应的空隙,假如使用文字 ...

  2. Android 开发 AirPlay Server

    安卓上开发  AirPlay Server  主要是参考了和修改了 DroidAirPlay项目 , 和Airplay 协议 1, 将DroidAirPlay 下载下来 2, Eclipse 新建一个 ...

  3. Week13(12月2日):又到了那个点,期末了~~~~

    Part I:提问 =========================== 1.ASP.NET MVC是微软.NET平台上的一个(      ). A.语言    B.集成开发环境    C.Web开 ...

  4. 二、Mongo命令初识

    简单介绍mongo的一些基本命令 1.   连接与登陆mongo 在命令行输入“mongo”命令即可登陆Mongo数据库(PS:默认讨论被信任的环境,也就是不需要用户名和密码进行登陆). 查看当前所使 ...

  5. 设计模式 ( 二十 ) 访问者模式Visitor(对象行为型)

    设计模式 ( 二十 ) 访问者模式Visitor(对象行为型) 1.概述 在软件开发过程中,对于系统中的某些对象,它们存储在同一个集合collection中,且具有不同的类型,而且对于该集合中的对象, ...

  6. HapiJS开发手冊

    HapiJS开发手冊 作者:chszs.转载需注明.博客主页:http://blog.csdn.net/chszs 一.HapiJS介绍 HapiJS是一个开源的.基于Node.js的应用框架,它适用 ...

  7. 高级UIKit-04(NSUserDefaults、NSKeyedArchiver、对象归档方法)

    [day05_1_UserDefault]:判断应用程序是否是第一次运行 NSUserDefaults:用来保存应用程序的配置信息如:程序运行次数,用户登陆信息等. // 使用系统提供的NSUserD ...

  8. 仿StackOverflow开发在线问答系统

    仿StackOverflow开发在线问答系统 [第二期11月9日开课]使用Python Flask Web开发框架实现一套类似StackOverflow的在线问答平台LouQA,具备提问,回答,评论点 ...

  9. [HTML5实现人工智能]小游戏《井字棋》发布,据说IQ上200才能赢

    一,什么是TicTacToe(井字棋)   本 游戏 为在下用lufylegend开发的第二款小游戏.此游戏是大家想必大家小时候都玩过,因为玩它很简单,只需要一张草稿纸和一只笔就能开始游戏,所以广受儿 ...

  10. java jni 编程

    最近要学习Java JNI 编程. 我使用的是的windows系统.装了一个cygwin. 根据 <JNI 编程规范和指南>. 文件网址: http://wenku.baidu.com/v ...