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 ...
随机推荐
- LVS前奏-ARP知识回顾
什么是ARP协议: ARP协议,全称“Address Resolution Protocol”(地址解析协议),使用ARP协议,可以实现将IP地址解析成对应主机的物理地址(MAC地址) 为了能够正确的 ...
- NOIP2018普及初赛解析
2018年第二十四届全国青少年信息学奥林匹克联赛初赛普及组真题解析 一.单项选择题 1. 以下哪一种设备属于输出设备:(D) A.扫描仪 _B.键盘C. 鼠标 _D. 打印机 解析:送分题,前三个都是 ...
- jsonwebtoken收藏博客地址
这个东西也不是很懂,但是查了一下资料,大概知道是什么了,具体要怎么嵌套到具体自己需要实现的功能里面,这个跨度还是有点大, 先把博客地址给收藏了. 这里是Java版示例 简书参考 js示例 github ...
- Tomcat Getshell
安装环境 账号密码路径:Tomcat6.0/conf/tomcat-users.xml 弱口令扫描工具 后台默认登陆地址:html://xx.xx.xx.xx/manager/html 后台war f ...
- Win10 清理自带APP
如果想一次性把它们全都删掉,请输入: Get-AppxPackage -AllUsers | Remove-AppxPackage 但是如果你先建一个账户,以上应用就会再次全部出现,不想这样的话可以输 ...
- ISP PIPLINE (八) RGB2YUV
what is the YUV? 暗电流来源1.YUV 是一种基本色彩空间, 人眼对亮度改变的敏感性远比对色彩变化大很多.亮度分量Y 要比色度分量U.V 重要得多. 所以, 可以适当地抛弃部分U.V分 ...
- Jquery中事件的重复绑定
问题:事件的绑定具有叠加效果,已有绑定的函数时,再次绑定,执行时会出现绑定多少次,触发多少次的情况 解决:1.on();绑定事件,提供了绑定事件处理程序所需的所有功能,用于统一取代以前的bind(). ...
- JS编码方式
1. escape(): 采用unicode字符集对指定的字符串除0-255以外进行编码.所有的空格符.标点符号.特殊字符以及更多有联系非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符 ...
- [LeetCode] N-ary Tree Preorder Traversal N叉树的前序遍历
Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary ...
- 【C++ 流类库与输入输出 】实验七
1. 基础练习 (1)教材习题 11-7 (2)教材习题 11-3 (3)教材习题 11-4 2. 应用练习 (1)已知有班级名单文件 list.txt(见实验 7 附件包).编写一个应用程序实现随机 ...