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

UVAoj 10057 a mid-summer night's dream (C语言) 用C语言实现,用较简单的方法实现找中间数 立即下载

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 (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


输出注意:

第一个数是最小的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;
}


无人机避障——卡内基梅隆大学(CMU)CERLAB 无人机自主框架复现 CMUCERLAB无人机自主框架是一个模块化的无人机自主导航系统,包含感知、测绘、规划和控制等组件。安装过程中遇到的主要问题包括:(1)cv_bridge路径未正确识别,需手动指定路径;(2)OpenCV版本冲突(4.2与4.6),导致动态导航节点崩溃。解决方案包括:完全卸载OpenCV4.2,重新编译安装OpenCV4.6,并修改相关CMakeLists文件指定版本。最终成功运行仿真环境,实现无人机在Gazebo和RViz中的自主避障导航功能。 阅读详情

相关推荐

哨兵2号遥感影像解析全流程:步骤、算法与AI应用详解

未来,多源数据融合与边缘计算技术的应用将进一步拓展遥感解析的边界。波段合成:选择10m分辨率波段(如B2、B3、B4、B8)进行Layer Stacking,生成多光谱影像。| 分类与识别 | Scikit-Learn、PyTorch | SVM、CNN、K-Means聚类 | 地块分类、目标检测 || 数据预处理 | SNAP、Sen2Cor | 大气校正、几何校正 | L2A产品生成、格式转换 || 波段融合 | ENVI、GDAL | Layer Stacking、重采样 | 多光谱影像合成 |

zhz5214的博客 2719

中位数的应用

对于中位数这个概念 , 一般都只是停留在初中时所学的知识 。 中位数:对长度为n的系列数据,根据数据大小排列得到的位于[(n+1)/2]位置上的数据。(百度百科) , 就是说给出n个数 , 排序 , 然后求出最终中间的那个数 , 如果n是偶数 , 那么中位数就是最中间那两个数的任意一个 。 应用:给出n个式子: x - a1 , x - a2 , x - a3 ........ , x - a

zengchenacmer的专栏 2840

【Unity动画系统】详解Root Motion动画在Unity中的应用(一)

什么时候勾选Bake into pose,当不希望动画带动游戏对象旋转时。在旋转的动画中一般是不用勾选的,因为就需要用它来带动我们的角色对象旋转。但在比如前进、后退、待机等动画来说,我们就可以勾选这里,以避免因动画文件本身的瑕疵而给我们带来的旋转。loop match:代表了这个动画在角度上的吻合度。如果这个动画在播放中转角过大,那么就会显示红色,告诉我们如果勾选bake into pose,则会带来不好的效果。

weixin_60154963的博客 6814

中位数应用

<br />中位数应用,那些未指明权值的默认权值为1,定义+例题,看完别说你还不懂!!!<br />中位数,编程问题中即n/2位置处的数,主要用的是带权中位数,带权中位数(Weighted Median),<br />其定义和中位数的差别在于:<br />中位数:n个元素集合中,第n/2小的元素。<br />带权中位数:对于n个互不相同的元素集合x1、x2……xn,其权重依次为w1、w2……wn。令W =<br />sigma(wi),则带权中位数xk满足:<br />    sigma(wi)(xi<XK

技术土豆 2224

车载监控系统升级指南:如何用XS9950A替换TP9950实现高清视频解码(附配置代码)

本文提供了从TP9950升级至XS9950A车载视频解码芯片的完整实战指南。详细解析了硬件设计调整、PCB布局要点,并重点分享了通过I2C配置寄存器实现高清HDCCTV视频解码与同轴音频集成的软件驱动代码与调试技巧,助力工程师平滑完成系统升级。

weixin_29268637的博客 387

什么是深度展开网络?如何将迭代算法的每一次迭代展开成深度网络对应的一层?深度展开网络进行端对端训练,其中端对端是什么意思?

在深度学习和机器学习的背景下,“端到端”(End-to-end)训练指的是将输入数据直接映射到最终输出的过程,而不需要任何中间的手动数据预处理或特征工程。- **自然语言处理**:端到端自然语言处理系统可以将自然语言输入直接转化为计算机可理解的语言输出,而不需要对语言进行分解和转化。- **推荐系统**:通过使用深度神经网络,端到端推荐系统可以直接根据用户历史行为预测其未来的兴趣爱好,并推荐相应的产品或服务。4. **直接映射**:从输入到输出的直接映射,中间没有任何拆分或分解的过程。

m0_67897882的博客 5476

UVaOJ10057 - A mid-summer night's dream.

10057 - A mid-summer night's dream. Time limit: 30.000 seconds   This is year 2200AD. Science has progressed a lot in two hundred years. Two hundred years is mentioned here because this problem

c随遇er安的专栏 731

vue 插件vue-awesome-swiper实现 三张图片,左右两边显示一半的效果的示例

希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

weixin_50450473的博客 3268

uva 10057 - A mid-summer night's dream.

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

yanshiqin4的专栏 674

Proteus+汇编+8086电子时钟实战:从框架搭建到中断驱动的核心实现

本文详细介绍了使用Proteus仿真软件和8086汇编语言实现电子时钟的完整过程。从程序框架搭建、内存分段模型理解,到核心的8259中断控制器配置与编程,再到中断服务程序编写和数码管动态扫描显示驱动,系统阐述了底层软硬件协同开发的核心原理与实战步骤。该项目是深入理解计算机中断机制和汇编语言编程的绝佳实践。

weixin_29189381的博客 425

微信支付开发之平台给用户转账到零钱的功能

请求消息中应包含商家批次单号、转账名称、appid、转账总金额、转账总笔数、转账openid、收款用户姓名等信息。批次已受理成功,若发起批量转账的30分钟后,转账批次单仍处于该状态,可能原因是商户账户余额不足等。【转账场景ID】 该批次转账使用的转账场景,如不填写则使用商家的默认场景,如无默认场景可为空,可前往“商家转账到零钱-前往功能”中申请。【转账总笔数】 一个转账批次单最多发起一千笔转账。【商家批次单号】 商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一。

程序员weixin_sodomany的博客 3463

UVa 10057 - A mid-summer night's dream.

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

ACM2272902662的专栏 892

Xilinx HydraMini试玩教程

HydraMini是Xilinx推出的基于Pynq-Z2开发板的自动驾驶开发小车,其有着简单易学、高灵活性、高扩展性、高性能等优良特性,是研究人员和学生进入自动驾驶领域的一个平台。本教程会通过最基础的讲解和步骤带领读者熟悉这个平台的基本开发流程。

qq_25762163的博客 1773

UVA10057 A mid-summer night's dream.【中位数】

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 p...

海岛Blog 657

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

UVA - 10057 - A mid-summer night's dream. (找中位数!)

UVA - 10057 A mid-summer night's dream. Time Limit: 30000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem C A mid-summer night’s

Never say never 1511

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

UVA 10057 A mid-summer night's dream. 仲夏夜之梦 求中位数

题意:求中位数,以及能成为中位数的数的个数,以及选择不同中位数中间的可能性。 也就是说当数组个数为奇数时,中位数就只有一个,中间那个以及中位数相等的数都能成为中位数,选择的中位数就只有一种可能;如果为偶数,中位数又两个,同样和那两个相等的数都能成为中位数,在[第一个中位数,第二个中位数]这一区间中拥有的整数个数就是所求的第三个数。 分类讨论,模拟即可。 代码: /* * Autho

水果君の日常 2526

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

UVA - 10057 A mid-summer night's dream.

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

小G的ACM之路 1317

Uva 10057 A mid-summer night's dream

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=998 题意:与10041Uva 10041 Vito's Family类似,只不过求得满足最小条件的数,给出的n个数中满足条件的数个数,和所有满足条件的数个数。 题解: 中位数最

Keaper的博客 504

UVA - 10057 A mid-summer night's dream

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=998 题意:其实就是给定数轴上n个点,求一个点与所有点的距离之和最小 思路:这个数一定是中位数,然后根据奇偶分别计算下就可以了。。做麻烦了 orz (代码没什么价值) AC代码:

可我只是梦呓,半生半生的无力 354

uva 10057 - A mid-summer night's dream

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

小shan在努力~ 643

【ICPC-84】uva 10057 - A mid-summer night's dream.

点击打开链接uva 10057 题目意思: 输入一序列数字X1.....Xn 给定一个表达式|X1-A| + |X2-A| + … … + |Xn-A|,要求找到整数A满足这个表达式值是最小的,A可能有多个 解题思路: 1:中位数是指一组数据按照从小到大后中处在中间的位置,它是这组数据里面能够反映数据的集中强度。由于我们要求|X1-A|+......|Xn-A| = |(X1...

藏经阁 | 玄苦 2639

uva10057 - A mid-summer night's dream

题目:uva10057 - A mid-summer night's dream 题目大意:给出n个数,A使得 (|X1-A| + |X2-A| + … … + |Xn-A|) is minimum,求最小的A,输入中A的个数,不同的A的个数。(A可能有多个值) 解题思路:要使得上面的式子最小,找出这个N个数的中位数。如果是奇数个数,那么中位数只有一个,不同的A的个数也只有一个

868

UVA - 10057 A mid-summer night's dream. 求中位数

题目大意:给出一系列的数字,要求求出中位数时多少,

静静地码 784

C - A mid-summer night's dream. UVA - 10057

此题找中位数 #include &amp;lt;iostream&amp;gt; #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; int main() { int a,i,k,n1,n2; int n[1000010]; while(cin &amp;gt;&amp;gt; a) { for(i=1; i&amp;lt;=a; ...

qq_44134712的博客 206
上一篇: TZC 1472 逆置正整数,去前导零 (java一句话秒杀)
下一篇: UVa 10487 Closest Sums (遍历&二分查找)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址