poj2388 快速排序 模板题

/** \brief poj2388
 *
 * \param date 2014/8/5
 * \param state AC
 * \return memory  time
 *   qsort 784K    110ms
 *   ksort 780K    172ms
 */

#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN=10000;
int Arr[MAXN];

/*
bool Comp(const int& a,const int& b)
{
    if(a!=b)return a<b;
    else return a>b;
}
*/
int Comp(const void* a,const void* b)
{
    return *(int* )a-*(int* )b;
}

void ksort(int l,int h,int a[])
{
    if(h<l+2)return ;
    int e=h,p=l;
    while(l<h)
    {
        while(++l<e && a[l]<=a[p]);
        while(--h>p && a[h]>=a[p]);
        if(l<h) swap(a[l],a[h]);
    }
    swap(a[h],a[p]);
    ksort(p,h,a);
    ksort(l,e,a);
}

int main()
{
    //cout << "Hello world!" << endl;
    //freopen("input.txt","r",stdin);
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        memset(Arr,0,sizeof(Arr));
        for(int i=0;i<N;i++)
        {
            cin>>Arr[i];
        }
        //
        //qsort(Arr,N,sizeof(Arr[0]),Comp);
        //cout<<Arr[N/2]<<endl;
        ksort(0,N,Arr);
        cout<<Arr[N/2]<<endl;
    }
    return 0;
}

poj2388 快速排序 模板题

时间: 2024-08-02 15:06:03

poj2388 快速排序 模板题的相关文章

hdu 2966 In case of failure kdtree模板题

问求每个点距离平方的最小的点 kd-tree模板题…… 1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(x) cerr<<#x<<"=="<<(x)<<endl 4 using namespace std; 5 typedef long long ll; 6 typedef pair<int,int>

几道树剖模板题

寒假后半段一直都在外出旅游..颓了好久..qaq 旅游期间写了几道树剖模板题,贴上来.. BZOJ 1036 没啥好说的,裸题 1 #include <cstdio> 2 #include <algorithm> 3 4 #define LEFT (segt[cur].l) 5 #define RIGHT (segt[cur].r) 6 #define MID (segt[cur].mid) 7 #define SUM (segt[cur].Sum) 8 #define MAX (

poj3630 Phone List (trie树模板题)

Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26328   Accepted: 7938 Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogu

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

洛谷P3381——费用流模板题

嗯..随便刷了一道费用流的模板题....来练练手. #include<iostream> #include<cstdio> #include<cstring> using namespace std; int h[5210],d[5210],used[5210],que[100010],last[5210]; int k=1,INF=0x7fffffff,ans1=0,ans2=0; inline int read(){ int t=1,num=0; char c=ge

HDU 1251 Trie树模板题

1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b #define F(i,a,b

LA 4670 出现次数最多的子串 (AC自动机模板题)

Dominating Patterns Time Limit:3000MS   Memory Limit:Unknown   64bit IO Format:%lld & %llu [Submit]  [Go Back]  [Status] Description The archaeologists are going to decipher a very mysterious ``language". Now, they know many language patterns; ea

【POJ 2104】 K-th Number 主席树模板题

达神主席树讲解传送门:http://blog.csdn.net/dad3zz/article/details/50638026 2016-02-23:真的是模板题诶,主席树模板水过.今天新校网不好,没有评测,但我立下flag这个代码一定能A.我的同学在自习课上考语文,然而机房党都跑到机房来避难了\(^o^)/~ #include<cstdio> #include<cstring> #include<algorithm> #define for1(i,a,n) for(i

hdu5384 AC自动机模板题,统计模式串在给定串中出现的个数

http://acm.hdu.edu.cn/showproblem.php?pid=5384 Problem Description Danganronpa is a video game franchise created and developed by Spike Chunsoft, the series' name is compounded from the Japanese words for "bullet" (dangan) and "refutation&q