UV-10057 a mid-summer night's dream.

Source: Internet
Author: User
Tags integer numbers

When an even number is used, the number between medians is acceptable (including medians)


When an odd number is specified, it must be the median.


For derivation, contact the junior high school teacher.


#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespace std;int box[1000000];int main(){    //freopen("in","r",stdin);    //freopen("out","w",stdout);    int i,n,a,b,c;    int num[65546];    while(cin>>n)    {        memset(num,0,sizeof(num));        for(i=0;i<n;i++)        {            cin>>box[i];            num[box[i]]++;        }        sort(box,box+n);        if(n%2||box[n/2-1]==box[n/2])        {            i=n/2;            a=box[i];            b=num[a];            c=1;        }        else        {            i=n/2-1;            a=box[i];            b=num[box[i]]+num[box[i+1]];            c=box[i+1]-box[i]+1;        }        cout<<a<<" "<<b<<" "<<c<<endl;    }    return 0;}

UV-10057

A mid-summer night's dream.
Crawling failed

Description

Problem C

A mid-summer Night's Dream

Input:Standard Input

Output:Standard output

This is year 2200ad. science has progressed a lot in two hundred years. two hundred years is mentioned here because this problem is being sent back to 2000ad with the help of time machine. now it is possible to establish direct connection between man and computer CPU. people can watch other people's dream on 3D displayer (that is the monitor today) as if they were watching a movie. one problem in T His century is that people have become so dependent on computers that their analytical ability is approaching zero. computers can now read problems and solve them automatically. but they can solve only difficult problems. there are no easy problems now. our chief scientist is in great trouble as he has forgotten the number of his combination lock. for security reasons computers today cannot solve Combination Lock related problems. in a mid-summer night the scientist has a dream where he sees a lot of unsigned integer numbers flying around. he records them with the help of his computer, then he has a clue that if the numbers are (x1, x2 ,..., Xn) he will have to find an integer numberA(ThisAIs the combination lock code) such that

(| X1-A | + | X2-A | +... ... + | Xn-A |) is minimum.

Input

Input will contain several blocks. each block will start with a number N (0 <n <= 1000000) indicating how many numbers he saw in the dream. next there will be n numbers. all the numbers will be less than 65536. the input will be terminated by end of file.

 

Output

For each set of input there will be one line of output. that line will contain the minimum possible value for. next it will contain in how many numbers are there in the input that satisfy the property of a (the summation of absolute deviation from a is minimum ). and finally you have to print how many possible different integer values are there for a (these values need not be present in the input ). these numbers will be separated by single space.

Sample input:

2
10
10
4
1
2
2
4

Sample output:

10 2 1
2 2 1

______________________________________________________________________________________________Shahriar Manzoor
16-12-2000

Source

Root: aoapc I: Beginning algorithm contests (rujia Liu): Volume 4. Algorithm Design
Root: Competitive programming 3: the new lower bound of programming contests (Steven & Felix Halim): data structures and libraries: linear data structures with built-in libraries :: c ++ STL algorithm (Java collections)

UV-10057 a mid-summer night's dream.

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.