UVA - 10057 A mid-summer night's dream.
偶数时,中位数之间的数都是能够的(包含中位数)
奇数时,一定是中位数
推导请找初中老师
#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;
}
UVA - 10057
| 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 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 (This
A 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
______________________________________________________________________________________________
Shahriar Manzoor
16-12-2000
Source
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: option=com_onlinejudge&Itemid=8&category=113">
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)
UVA - 10057 A mid-summer night's dream.的更多相关文章
- UVA 10057 A mid-summer night's dream. 仲夏夜之梦 求中位数
题意:求中位数,以及能成为中位数的数的个数,以及选择不同中位数中间的可能性. 也就是说当数组个数为奇数时,中位数就只有一个,中间那个以及中位数相等的数都能成为中位数,选择的中位数就只有一种可能:如果为 ...
- UVa 10057 - A mid-summer night's dream
题目大意:给n个数,找一个数A使得A与这n个数的差的绝对值最小.输出A最小的可能值,n个数中满足A的性质的数的个数以及满足A性质的不同的数的个数(不必从这n个数中挑选). 看见绝对值就想到了数轴上点之 ...
- POJ 2411 Mondriaan's Dream
状压DP Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9938 Accepted: 575 ...
- poj 2411 Mondriaan's Dream 【dp】
题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...
- POJ 2411 Mondriaan's Dream (dp + 减少国家)
链接:http://poj.org/problem?id=2411 题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形.求拼成指定的大矩形有几种拼法. 參考博客:http://blog.csdn. ...
- 状压dp Mondriaan's Dream poj2411
超经典的一道题目,实现这题的方法也有非常多种 1.利用DFS建立矩阵,然后通过高速矩阵幂得到答案(运用于min(m,n)比較小.可是max(m,n)很大的情况) 2.利用dp状压解决 第一种在我的还有 ...
- zoj 1100 - Mondriaan's Dream
题目:在m*n的地板上铺上同样的1*2的地板砖,问有多少种铺法. 分析:dp,组合,计数.经典dp问题,状态压缩. 状态:设f(i,j)为前i-1行铺满,第i行铺的状态的位表示为j时的铺砖种类数: 转 ...
- [ACM] HDU 1400 Mondriaan's Dream (状态压缩,长2宽1长方形铺满)
Mondriaan's Dream Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 【uva 714】Copying Books(算法效率--二分+贪心)
题意:将1个含N个正整数的序列划分成K个连续的子序列,使每段的和的最大值尽量小,问字典序最小的划分方案. 解法:由于是连续的数的"最大值最小",便可想到二分每段的最大值,若这时可分 ...
随机推荐
- Sicily-1156
一. 模仿树的的先序遍历.范围是1000个节点.用数组存储节点的信息. 二. 要注意的是,头结点是不确定的,所以在前序遍历之前要找出头结点,除了头结点的下标值出现一次之外,其他结点 ...
- poj 1386 Play on Words(有向图欧拉路+并查集)
题目链接:http://poj.org/problem?id=1386 思路分析:该问题要求判断单词是否能连接成一条直线,转换为图论问题:将单词的首字母和尾字母看做一个点,每个单词描述了一条从首字母指 ...
- 统计难题(trie树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- Objective-c 程序结构
类是Objective-c的核心,Objective-c程序都是围绕类进行的.Objective-c程序至少包含以下三个部分: 1.类接口:定义了类的数据和方法,但是不包括方法的实现代码. 2.类实现 ...
- 指尖上的电商---(2)Solr全文搜索引擎的准备工作
Solr是一个基于Lucene的全文搜索引擎.提供了更丰富的搜索语言.更灵活的配置.更高的查询效率. 一句话.与Lucene相比.有过之而无不及.这一节里, 主要谈论两个知识点:Jdk的安装和Tomc ...
- poj 3026 Borg Maze bfs建图+最小生成树
题目说从S开始,在S或者A的地方可以分裂前进. 想一想后发现就是求一颗最小生成树. 首先bfs预处理得到每两点之间的距离,我的程序用map做了一个映射,将每个点的坐标映射到1-n上,这样建图比较方便. ...
- Swift和OC 混编
1.首先创建一个Swift工程 2.导入或者创建一个OC文件(.h和.m) 3.再创建一个桥连接文件 4.然后文件样子为 5.在桥接链接里面导入头文件 6.通过targets->->bui ...
- PHP 时间和日期 总结
PHP 时间戳 UNIX 时间戳(timestamp)是 PHP 中关于时间日期一个很重要的概念,它表示从 1970年1月1日 00:00:00 到当前时间的秒数之和. 可以使用time()函数来获取 ...
- JS实现常用的分享到按钮
我们阅读博客的时候经常会用到这样功能,当然有时候也会想把自己的网站上也加入类似的分享功能,各大厂商已经给出了相应的API,点击一个按钮即可弹出窗口进入分享,我们事先可以设置一些参数,一般常用的就是 网 ...
- 亲测VS2010纯静态编译QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序(图文并茂,非常详细)
下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip,不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0- ...