题意; 寻找中位数 利用快速排序来寻找中位数. #include <iostream> using namespace std; int N; ]; int Median(int left,int right,int pos){ ,r=left; int pirior=op[right]; for(int i=left;i<right;i++){ if(op[i]<pirior){ int temp=op[i]; op[i]=op[r]; op[r]=temp; r++; l++;…
/** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=10000; int Arr[N]; void insertSort(int len) { for(int j=1;j<len;…
排序(水题)专题,毕竟如果只排序不进行任何操作都是极其简单的. 事实上,排序算法十分常用,在各类高级的算法中往往扮演着一个辅助的部分. 它看上去很普通,但实际的作用却很大.许多算法在失去排序后将会无法实现. 以上在扯P 看2388,求中位数. 好,sort一遍(与衢州2017市赛PJ T1一样水). CODE #include<cstdio> #include<algorithm> using namespace std; ; int n,a[N]; inline char tc(…
一.Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give as much or more than the median; half give as much or less. Given an odd number of cows N (1 <= N < 10…
题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #include<algorithm> using namespace std; int main() { int n; while(scanf("%d",&n)!=EOF) { ]; ; i<n; i++) scanf("%d",&na[i…
点击打开链接 Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28324   Accepted: 16396 Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cow…
[题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并把区间划分成小于这个数和大于这个数的两个子区间,此时便可以判断这个数是不是第k大项,如果比K大,则去左区间找,否则去右区间找. #include #include #include #include #include using namespace std; template doubleORint…
Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31149   Accepted: 18073 Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give…
Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31015   Accepted: 17991 Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median' cow gives: half of the cows give…
http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #include <stdio.h> #include <string.h> ],ans,n; void inset(int x,int y) //插入,并排序. { int i; ] > x;i /= ) arr[ i ] = arr[ i / ]; arr[ i ] = x; } {…