UVa 10057 A mid-summer night ' s dream

Source: Internet
Author: User
Tags integer numbers time limit

UVa 10057 A mid-summer night ' s dream. (b & what can be taken as the median number?) )

10057-a mid-summer night ' s dream.

Time limit:30.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=998

This is year 2200AD. Has progressed a lot in two hundred years. Two hundred years is mentioned here because this problem are being sent back to 2000AD with the help of time machine. Now it's possible to establish direct connection between Mans and computer CPU. People can watch other people ' s Dream on 3D Displayer (which is the monitor today) as if they were watching a movie. One problem in this century was that people have become then dependent on computers then their analytical ability is approach ing 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 are in great trouble as him has forgotten the number of his combination lock. For the 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. He records them and the help of his computer, Then hE has a clue that if the numbers are (X1, X2,   ...   Xn) He'll have to find an integer number A (Thisa is the Combination lock code) such that

(| x1-a| + | x2-a| + ... + | xn-a|) is minimum.

Input

Input would contain several blocks. Each block would start with a number n (0<n<=1000000) indicating how many numbers the him saw in the dream. Next there would be n numbers. All the numbers would be less than 65536. The input is terminated by end of.

Output

For each set of input there is one line of output. That line would contain the minimum possible value for A. Next it would contain how many numbers are there in the "satisfy" the property of A (the summation of absolute dev Iation from A is minimum). And finally you have to print how many possible different the integer values are there for A (this values need not being present In the input). These numbers'll are separated by single.

Sample Input:

2
10
10
4
1
2
2
4
Sample output:10 2 1
2 2 1
Output Note:

The first number is the smallest a, the second number is in the series {Xn} How many numbers can be a, the third number is in the number of numbers can be a.

Complete code:

/*0.245s*/
    
#include <cstdio>  
#include <algorithm>  
using namespace std;  
#define SF scanf  
#define PF printf  
    
int a[1000005];  
    
int main ()  
{  
    int n, m, I;  
    while (~SF ("%d", &n))  
    {  
        m = (n-1) >> 1;  
        for (i = 0; i < n; ++i)  
            SF ("%d", &a[i]);  
        Sort (A, a + N);  
        PF ("%d%d%d\n", A[m], ((n & 1) = = 0? upper_bound (A, a + N, a[m + 1)): Upper_bound (A, a + N, a[m])-Lower_bound (A, A + N, A[m]), ((n & 1) = = 0 && a[m]!= a[m + 1]? a[m + 1]-a[m] + 1:1);  
    }  
    return 0;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.