UVa 10057 A mid-summer night's dream

UVa 10057 A mid-summer night's dream. (二分&可以取哪些作为中位数?)

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. 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 this 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 number A (ThisA is 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 A. Next it will contain 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
输出注意:

第一个数是最小的A,第二个数是在数列{Xn}中有多少个数可以是A,第三个数是在有多少个数可以是A。

完整代码:

/*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;
}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, 蓝牙 lot in he and
, is
, The
, problem
that
uva summer、one summer night、summer dream、summer night、summer dream lab,以便于您获取更多的相关知识。

时间: 2024-09-17 04:13:40

UVa 10057 A mid-summer night's dream的相关文章

UVa 10057:A mid-summer night&#039;s dream.

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=998 原题: This is year 2200AD. Science has progressed a lot in two hundred years. Two hundred years is mentioned here because thi

UVA之12124 - Assemble

[题目] Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to practice for programming contests is not good enough anymore. Therefore, you decide to buy a new computer. To make the ideal computer for your nee

UVa 1422:Processor 任务处理问题

题目大意:有n个任务送到处理器处理,每个任务信息包括r,d,w,r代表开始时间,w代表必须要结束的时间,w指需要多少时间处理. 其中处理器的处理速度可以变速,问处理器最小需要多大速度才能完成工作? 输入: 3 5 1 4 2 3 6 3 4 5 2 4 7 2 5 8 1 6 1 7 25 4 8 10 7 10 5 8 11 5 10 13 10 11 13 5 8 15 18 10 20 24 16 8 15 33 11 14 14 1 6 16 16 19 12 3 5 12 22 25

UVa 10341: Solve It

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1282 原题: Solve the equation:        p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0        where 0 <= x <= 1. Input

UVa 10340:All in All

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1281 原题: You have devised a new encryption technique which encodes a message by inserting between its characters randomly gener

UVa 10132:File Fragmentation

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1073 类型: 贪心+回溯 原题: The Problem Your friend, a biochemistry major, tripped while carrying a tray of computer files through the l

UVa 10245:The Closest Pair Problem

[链接] http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1186 [原题] Given a set of points in a two dimensional space, you will have to find the distance between the closest two points.

UVa 10041:Vito&#039;s Family

[链接] http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=982 [原题] Background The world-known gangster Vito Deadstone is moving to New York. He has a very big family there, all of them

uva 10688:The Poor Giant(区间dp)

题目链接: uva-10688 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=514&page=show_problem&problem=1629 题意 有n个苹果,和一个数k,第i个苹果的重量是k+i(1<=i<=n). 已知其中只有一个苹果是甜的, 所有比它重量轻的都是苦的,比它重的都是酸的. 为了要找出甜的苹果,就要去一个一个地吃它,且吃了咬了苹果