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个连续的子序列,使每段的和的最大值尽量小,问字典序最小的划分方案. 解法:由于是连续的数的"最大值最小",便可想到二分每段的最大值,若这时可分 ...
随机推荐
- HDU 1507 Uncle Tom's Inherited Land*
题目大意:给你一个矩形,然后输入矩形里面池塘的坐标(不能放东西的地方),问可以放的地方中,最多可以放多少块1*2的长方形方块,并输出那些方块的位置. 题解:我们将所有未被覆盖的分为两种,即分为黑白格( ...
- java实现字符串匹配问题之求两个字符串的最大公共子串
转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/38924981 近期在项目工作中有一个关于文本对照的需求,经过这段时间的学习,总结 ...
- 【剑指offer】调整数组顺序
转载请注明出处:http://blog.csdn.net/ns_code/article/details/25829395 剑指offer上的第14题,九度OJ为了确保输出的结果的唯一性,在输出上做了 ...
- Lamd表达式
1. 普通绑定: public void button1_Click(object sender, EventArgs e) { MessageBox.Show("ok"); } ...
- xampp中mysql设置密码
发现网上的解决办法都比较过时.嗯,解决办法很简单. 打开浏览器localhost:[port]/phpmyadmin/ 点击用户账户选项 选择用户名为root,Host name为localhost也 ...
- [html5] canvas 绘图:八卦图
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title&g ...
- matlab之kmeans聚类用法
kmeans函数用法如下: [IDX,C,sumd,D] = kmeans(X,2,'Distance','city','Replicates',5,'Options',opts); 参数含义如下:I ...
- hdu 4779 Tower Defense 2013杭州现场赛
/** 题意: 有两种塔,重塔,轻塔.每种塔,能攻击他所在的一行和他所在的一列, 轻塔不 能被攻击,而重塔可以被至多一个塔攻击,也就是说重塔只能被重塔攻击.在一个n*m 的矩阵中,最少放一个塔,可放多 ...
- spoj 3871 gcd extreme
题目大意给出一个n,求sum(gcd(i,j),<i<j<=n); 可以明显的看出来s[n]=s[n-]+f[n]; f[n]=sum(gcd(i,n),<i<n); 现 ...
- 【xcode】错误之Could not launch "" failed to get the task for process
http://blog.csdn.net/teng_ontheway/article/details/8467932 在Xcode下编译工程正常,在模拟器下运行正常,最后在真机上运行的时候出现了如下错 ...