space=1&num=1457">1457. Heating Main

Time limit: 1.0 second

Memory limit: 64 MB

Background

I like my hometown very much. Those dilapidated buildings rising proudly above the city and streets dug up as far back as the last century inspire me greatly. Crowds of everlastingly offended working class representatives, stupid
students escaping the army, retirees hunting for empty bottles, extremely nice vagrants and amiable young people wearing black caps, leather jackets and baseball bats - all of them are so close to me.
Furthermore, an old man lives in the city. To be more precise, he had lived in the city until his house was demolished and a new casino was built on its place. No wonder, because the casino is much more useful for the city than
some old man. The foundations of market economy are impossible to resist.
So the old man had to resettle into a heating main, which lies straight under the city. Despite all its disadvantages, inhabitation in a heating main implies free water supply, heating and no rent at all. In short, the old man
is going to live a worth old age. Thank the government and the President for such a great concern.
No matter how gorgeous a life in the heating main is, it is necessary for the old man to get out from the heating main to the city and visit one of some important places. Sometimes he has to make sure that there are no free drugs
at the clinic, provide himself with foodstuffs at the market dump, get a pension at the post-office or give this pension to the grandson - it is just enough to buy an ice cream!

Problem

The heating main was build under Stalin, so it is a straight branchless tunnel. Each point of it is defined by its main offset. The main offset of the start point, which is located under the courthouse, is zero. The distance
between any two points of the heating main equals to the absolute value of the difference between their main offsets.
It appeared that the heating main lies under all N places visited by the old man. For each gulley, which leads from the heating main straight to one of the places, the main offset P[i] was found. The old man can get out from
the heating main through these gulleys only. If he tries to use another gulley, he would be immediately caught by watchful policemen as a dangerous vagrant.
The old man is rather old, and his effort to pass some distance is proportionate to the square of this distance. That is why the old man would like to live in some point of the heating main so that the arithmetic mean of the
efforts to reach each of the places is minimal.

Input

The first line contains the integer number N (1 ≤ N ≤ 1000). The second line contains N integer numbers P[i] (0 ≤ P[i] ≤ 106).

Output

You should output the main offset of the desired point. The offset should be printed with at least six digits after decimal point. If the problem has several solutions, you should output any of them.

Sample

input output
3
7 4 5
5.333333

Problem Author: Nikita Rybak, Dmitry Kovalioff, Ilya Grebnov

Problem Source: Timus Top Coders: Second Challenge

解析:ans = sum(P[i]) / n

AC代码:

#include <bits/stdc++.h>
using namespace std; int main(){
int n, x;
while(~scanf("%d", &n)){
int sum = 0;
for(int i=0; i<n; i++){
scanf("%d", &x);
sum += x;
}
printf("%.6lf\n", (double)sum / n);
}
return 0;
}

URAL 1457. Heating Main的更多相关文章

  1. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

  2. poj 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 678   Accepted: 310 Des ...

  3. NBUT 1457 莫队算法 离散化

    Sona Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Submit Status Practice NBUT 145 ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  9. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

随机推荐

  1. HBase使用flush命令之后存储的位置

    HBase使用flush命令之后存储的位置 根据系统安装位置的不一样而不一样,当前是在: hadoop fs -ls /apps/hbase/data/data/default/t1 下面: 使用ha ...

  2. robot framework环境配置

    1.Robot framework的安装 作用:web自动化测试框架. RF框架是基于python 的,所以一定要有python环境.网上可以自行查找. 下载地址:https://pypi.pytho ...

  3. 杂项:MSP(管理服务提供商)

    ylbtech-杂项:MSP(管理服务提供商) 随着外包市场的日益成熟,为了满足企业的需求,一个全新的业务方向被开发出来—MSP.MSP采用业界领先的系统管理技术,由经验丰富的系统管理专家通过WAN为 ...

  4. vmvare如何安装xp虚拟机

    http://jingyan.baidu.com/article/a681b0ded8e25e3b19434640.html 一直以来,许多的朋友都不熟悉怎么安装在虚拟机上装windows系统 200 ...

  5. vue项目中遇到的打印,以及处理重新排版后不显示echarts图片问题。

    1. 项目中用到的打印 页面: css: 控制好宽度一般A4 我调试的是794px多了放不下,小了填不满.当时多页打印的时候,一定要控制好每一个页面内容显示的高度不要超过一个页面,当然根据自己项目来. ...

  6. 看似简单!解读C#程序员最易犯的7大错误

    编程时犯错是必然的,即使是一个很小的错误也可能会导致昂贵的代价,聪明的人善于从错误中汲取教训,尽量不再重复犯错,在这篇文章中,我将重点介绍C#开发人员最容易犯的7个错误. 格式化字符串 在C#编程中, ...

  7. 懒人npm运行和打包命令

    源码: @echo off&setlocal EnableDelayedExpansion & color 3e :start title npm 常用命令 by:ceet@vip.q ...

  8. cache(缓存)的作用

    cache的作用: 连接文件.内存与应用,为信息流在三者之间流动提供通道: 存储管理:对外与对内: 存取效率: 多线程: 一次存储:分批存储? 系统的缓存控制机制(虚拟内存)使用分段分页与命中机制. ...

  9. CDR X7正版优惠,3折来袭,好礼相送,行不行动?

    意料之中的是,CorelDRAW系列软件在618期间成绩再次突破历史,成为新高.因为X7版本活动在6月15号的才上, 加之在此之前从没有过X7的活动优惠,势头之猛,可想而知,如此一来,官方预定的限量2 ...

  10. day07 分支,循环

    目录 if(分支) if的语法 if...else... if...elif...else if的嵌套 for循环 for-else 语句 for循环的嵌套(重要) range介绍 while循环 w ...