Median
#include <stdio.h>
#include <stdlib.h>
#include <math.h> #define MAXSIZE 1000 int comp_inc(const void *first, const void *second); int main()
{
int Median_ind_1;
int Median_ind_2;
int n;
scanf("%d", &n);
int i;
int seq[MAXSIZE];
for(i=0; i<n; ++i)
scanf("%d", &seq[i]);
qsort(seq, n, sizeof(seq[0]), comp_inc);
for(i=0; i<n; ++i)
{
if(i!=0)
printf(" ");
printf("%d", seq[i]);
}
printf("\n");
Median_ind_1=ceil(n/2);
int temp=n-1;
Median_ind_2=((temp-1)/2)+1;
printf("Median_ind_1=%d; Median=%d\n", Median_ind_1, seq[Median_ind_1]);
printf("Median_ind_2=%d; Median=%d\n", Median_ind_2, seq[Median_ind_2]);
return 0;
} int comp_inc(const void *first, const void *second)
{ return *(int *)first-*(int *)second;
}
Median的更多相关文章
- No.004:Median of Two Sorted Arrays
问题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...
- [LeetCode] Find Median from Data Stream 找出数据流的中位数
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- [LeetCode] Median of Two Sorted Arrays 两个有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- Applying vector median filter on RGB image based on matlab
前言: 最近想看看矢量中值滤波(Vector median filter, VMF)在GRB图像上的滤波效果,意外的是找了一大圈却发现网上没有现成的code,所以通过matab亲自实现了一个,需要学习 ...
- 【leetcode】Median of Two Sorted Arrays
题目简述: There are two sorted arrays A and B of size m and n respectively. Find the median of the two s ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
- 【leedcode】 Median of Two Sorted Arrays
https://leetcode.com/problems/median-of-two-sorted-arrays/ There are two sorted arrays nums1 and num ...
- Find Median from Data Stream
常规方法 超时 class MedianFinder { vector<int> coll; public: MedianFinder(){ } void heapfu(vector< ...
- 数据结构与算法(1)支线任务8——Find Median from Data Stream
题目如下:(https://leetcode.com/problems/find-median-from-data-stream/) Median is the middle value in an ...
- leetcode-【hard】4. Median of Two Sorted Arrays
题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...
随机推荐
- python3列表(list)
一.列表(List) 定义:有序的可变的元素集合:通过range函数构造,在python3 中用的时候才会去构造 list = [1,2,3,4,5,'abc',['a',1,2,3],6,7] ...
- zTree 3-- jQuery 树插件笔记
地址:http://www.treejs.cn/v3/demo.php#_507 数据结构json,里可以自定义属性. var zNodes =[ { name:"父节点1 - 展开&quo ...
- Jarvis OJ 一些简单的re刷题记录和脚本
[61dctf] androideasy 164求解器 50 相反 脚本如下: s='' a=113, 123, 118, 112, 108, 94, 99, 72, 38, 68, 72, 87, ...
- 如何配置.Net Core Centos守护进程配置
一.安装supervisor 运行命令 yum install supervisor 二.配置supervisor 1.运行命令创建文件夹 mkdir -p /etc/supervisor/conf. ...
- 【转】C# 串口操作系列(1) -- 入门篇,一个标准的,简陋的串口例子。
C# 串口操作系列(1) -- 入门篇,一个标准的,简陋的串口例子. 标签: c#objectnewlineexceptionbytestring 2010-05-17 01:10 117109人阅读 ...
- 【AtCoder】【模拟】【模型转化】Camel and Oases(AGC012)
题意: 有一个骆驼,n个绿洲遍布在数轴上,第i个绿洲的坐标为x[i],保证x[i]单增.骆驼的驼峰有体积初始值V.当驼峰的体积变为v的时候,驼峰中至多只能够存储v L的水.骆驼希望走完所有的绿洲,并且 ...
- Data Science Project
https://drivendata.github.io/cookiecutter-data-science/
- css 浮动布局,清除浮动
浮动的特性: (1)浮动元素有左浮动(float:left)和右浮动(float:right)两种 (2)浮动的元素会向左或向右浮动,碰到父元素边界.其他元素才停下来 (3)相邻浮动的块元素可以并在一 ...
- 【C语言程序】基因编码
输入一个长为n=2k(k≤8)01串s,按照"ABC编码规则"进行编码,ABC编码规则是: A //若s串全是0 T(s)= ...
- JS对象3
1.BOM对象 window对象 所有浏览器都支持window对象 概念上讲:一个html文档对应一个window对象 功能上讲:控制浏览器窗口的 使用上讲:window对象不需要创建对象,直接使用即 ...