//poj2388 int partition(int a[],int left,int right)//模拟一次排序 two pointer技巧 M每次首尾巴指针相遇截至 //不用排序,只用不断匹配,直到有一次找到的该在本位置的数是中位数即可,减//少时间 { int temp=a[left]; while(left<right) { while(left<right&&a[right]>=temp) right–; a[left]...
POJ 2388 基数排序 这题可以直接nth_element过去 比如这样子 //By SiriusRen#include<cstdio>#include<algorithm>usingnamespacestd;intn,a[100500];intmain(){scanf("%d",&n);for(inti=1;i<=n;i++)scanf("%d",&a[i]);nth_element(a+1,a+n/2+1,a+1+n);printf("%d\n",a[n/2+1]); }...
1.POJ2388 求中位数问题时间限制:1000ms;空间限制:65536KB。问题描述:FJ正在调查他的牛群以寻找最普通的牛群,他想知道产奶量的中位数,一半奶牛的产奶量与中位数一样多或更多,一半奶牛的产奶量与中位数一样多或更少。输入格式:给定n(n为奇数, 1≤n10000) 头牛的牛奶产量 (1∼1000000) ,找到这些奶牛中...
POJ 2388,题目链接http://poj.org/problem?id=2388 题意: 水题一道 给定n个数,输出中间值,可以用sort,干脆快捷。 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 //396K 32MS #include <cstdio> #include <algorithm> intbuf[10000]; intmain() { intcowsNum; sc...
POJ(2299,2388) 2299思路 1.题目意思首先要搞清楚;大致意思为将一个序列进行排序,排序为递增序列;这个过程中所需要进行的交换(adjacent swap;特指相邻元素的交换)最少的操作有多少? 2.看到这个题目首先我想到的是使用冒泡排序,因为它的排序算法过程中就是相邻两个元素在比较;那么记录算法里边的交换次数就可以了。
POJ 2388 - Who's in the Middle,排序的水题,主要拿来测试了一下快速排序和归并排序哪个速度快一点。当然单纯的一道题目其实完全说明不了什么问题……顺手再贴一个写法更加得劲儿一点的归并排序……
POJ 刷题系列:2388. Who’s in the Middle 传送门: 2388. Who’s in the Middle 题意: 给定n个数,从小到大排列,求出中间大的数。 思路: 直接排序,调用接口就非常方便了。 代码如下: import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException...
POJ2388题意: 【输入】第一行为n,接下来n行分别为一个数; 【输出】这n个数排序后的中位数 样例: Sample Input 5 2 4 1 3 5 Sample Output 3 分析:好象用多种排序法都可以AC,这里先用堆排序,主要是复习一下堆排序代码。 排一次序后输出中位数,但效率太低了。这里先不管了。
poj 2388 //poj 2388#include<stdio.h>#include<algorithm>usingnamespacestd;constintmaxn=10005;inta[maxn];intpartition(intl,intr){intx=a[r];intol=l;for(inti=l;i<r;i++){if(a[i]<x){swap(a[ol],a[i]);ol++;}}swap(a[r],a[ol]);returnol;}intsearch(intl,intr,intk){intpos=pa...
题目链接:Who's in the Middle,题目与排序有关,使用快排实现 packagecom.test;importjava.util.Scanner;publicclassMain{publicstaticintpartition(Integer[]arr,intfirst,intlast){intlow=first;intend=last;intkey=arr[first];//取数组第一个数为轴值while(low<end){//首先从右向左寻找第一个比轴值小的数,...