URAL 1457. Heating Main

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;
}
时间: 2024-12-14 04:02:00

URAL 1457. Heating Main的相关文章

阿斯顿撒爱上

http://p.baidu.com/itopic/main/qlog?qid=b7876162633432353462372600&type=questionlog http://p.baidu.com/itopic/main/qlog?qid=cb876162636633366661632600&type=questionlog http://p.baidu.com/itopic/main/qlog?qid=cd876162633865373635322600&type=que

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

ural 1272. Non-Yekaterinburg Subway

1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construct a subway. The peculiarity of the town is that it is located on small islands, some of them are connected with tunnels or bridges. The mayor is

ural 1273. Tie

1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work under the ground and… Well, they are not angels. And where have you seen angels? It is all in a lifetime! Show me first somebody who has never… and t

ural 1269. Obscene Words Filter

1269. Obscene Words Filter Time limit: 0.5 secondMemory limit: 8 MB There is a problem to check messages of web-board visitors for the obscene words. Your elder colleagues commit this problem to you. You are to write a program, which check if there i

ural 1218. Episode N-th: The Jedi Tournament

1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Knights to organize a tournament once. To know, accumulates who the largest amount of Force. Brought each Jedi his lightsaber with him to the tourn

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

ural 1219. Symbolic Sequence

1219. Symbolic Sequence Time limit: 1.0 secondMemory limit: 64 MB Your program is to output a sequence of 1 000 000 lowercase Latin letters. This sequence should satisfy the following restrictions: Every letter occurs not more than 40 000 times in th