POJ 2388 Who's in the Middle (排序 快排复习)
来源:互联网 发布:oppo wlan 移动数据 编辑:程序博客网 时间:2024/06/01 11:50
题目链接:http://poj.org/problem?id=2388
题目大意是说有奇数个母牛,已知每只母牛的产奶量,求产奶量的中位数
这几天刷POJ刷伤了,在刷题计划里找几个水题缓解一下心情。 = =,记得在寒假和山建比赛的时候这个还做过签到题
这个题就是一个排序加取中位数,本来就是奇数只奶牛,这样连分类讨论都省了。
本来想一个sort水过去,不过想想好久没自己写快排函数了,为了水出水平,就捎带复习一下快排函数吧。
1Y的感觉就是好= =、
代码如下:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int num[1000000];int qp (int *lif,int *rig){ if (lif >= rig) return 0; int *l = lif,*r = rig; int w = *l; while (l < r) { while (l < r && *r >= w) r--; *l = *r; while (l < r && *l <= w) l++; *r = *l; } *l = w; qp(lif,r - 1); qp(l + 1,rig);}int main(){ int n; while (~scanf ("%d",&n)) { for (int i = 0;i < n;i++) scanf ("%d",&num[i]); qp(num,&num[n - 1]); printf ("%d\n",num[(int)(n / 2)]); } return 0;}
0 0
- POJ 2388 Who's in the Middle (排序 快排复习)
- POJ 2388 Who's in the Middle 快排解法
- poj 2388 Who's in the Middle——快排
- POJ2388 Who's in the Middle 快排
- Who's in the Middle(简单快排)
- poj2388 Who's in the Middle 快排
- POJ 2388 Who's in the Middle(排序)
- POJ 2388 Who's in the Middle(堆排序)
- POJ 2388 Who's in the Middle 排序
- poj 2388 Who's in the Middle【sort排序】
- Who's in the Middle 堆排序,poj 2388
- POJ 2388 Who's in the Middle(排序)
- poj 2388 Who's in the Middle 排序,大水
- Poj 2388 Who's in the Middle【排序】
- poj 2388Who's in the Middle 排序
- POJ--2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ-2388 who's in the middle
- makefile笔记
- HDU 1012 u Calculate e(水题)
- Hadoop的整文件读取
- HLG1134
- A标签触发onclick事件而不跳转
- POJ 2388 Who's in the Middle (排序 快排复习)
- OFDM的MATLAB仿真
- Hadoop的多文件输出及自定义文件名
- LG nexus5刷机、救砖教程
- android sqlite一些使用介绍
- (转)Unity3d使用心得(2):Unity3d 动态下载动画资源——AnimationClip 的使用 - 斯玛特琦
- OJ2536长方体继承自矩形
- 创建Lua工程脚本
- objcopy和objdump使用教程