URAL 1457. Heating Main

Source: Internet
Author: User
Tags integer numbers

1457. Heating Main
Time limit:1.0 Second
Memory limit:64 MB
Backgroundi 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 gr eatly. Crowds of everlastingly offended working class representatives, stupid students escaping the army, retirees hunting for EM Pty bottles, extremely nice vagrants and amiable young people wearing black Caps, leather jackets and baseball bats-all Of them is so close to me. Furthermore, the lives in the city. To is more precise, he had lived in the city until his house is demolished and a new casino is built on its place. No wonder, because the casino is much more useful in the city than some old man. The foundations of the market economy is impossible to resist. Had to resettle into a heating main, which lies straight under the city. Despite all it disadvantages, inhabitation in a heating main implies free water supply, heating and no rent at all. In short, the old mans is going to live a worth. Thank the government and the President for such a great concern. No matter how gorgeous a life in the heating main is, it's 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 is no free drugs at the clinic, provide himself with foodstuffs at the market du MP, get a pension at the post-office or give this pension to the grandson-it are just enough to buy an ice cream! Problemthe Heating main was build under Stalin, so it's a straight branchless tunnel. Each point of it was defined by its main offset. The main offset of the start point, which is located under the courthouse, is zero. The distance between any and points of the heating main equals to the absolute value of the difference between their main Offsets. It appeared 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 mans can get out from the heating main through these gulleys only. If he tries to use another gulley, he would is immediately caught by watchful policemen as a dangerous vagrant. The old man was rather old, and he effort to pass some distance was proportionate to the square of this distance. That's why, the old man would-like-to-live in some point of the heating main so, the arithmetic mean of the efforts to Reach each of the places is minimal. Inputthe first line contains the integer number N (1≤n≤1000). The second line contains N integer numbers p[i] (0≤p[i]≤106). Outputyou should output the main offset of the desired point. The offset should is printed with at least six digits after decimal point. If the problem has several solutions, you should output any of them. Sample
input Output
37 4 5
5.333333
problem Author:Nikita Rybak, Dmitry kovalioff, Ilya Grebnov
problem Source:Timus Top Coders:second Challenge




Parse: ans = SUM (p[i])/n




AC Code:

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.