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 高速排序 模板题的更多相关文章
- HDU 1285 确定比赛名次 拓扑排序模板题
http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...
- HDU 1814 Peaceful Commission / HIT 1917 Peaceful Commission /CJOJ 1288 和平委员会(2-sat模板题)
HDU 1814 Peaceful Commission / HIT 1917 Peaceful Commission /CJOJ 1288 和平委员会(2-sat模板题) Description T ...
- 【后缀数组】洛谷P3809模板题
题目背景 这是一道模板题. 题目描述 读入一个长度为 n n n 的由大小写英文字母或数字组成的字符串,请把这个字符串的所有非空后缀按字典序从小到大排序,然后按顺序输出后缀的第一个字符在原串中的位置. ...
- HDU 4347 - The Closest M Points - [KDTree模板题]
本文参考: https://www.cnblogs.com/GerynOhenz/p/8727415.html kuangbin的ACM模板(新) 题目链接:http://acm.hdu.edu.cn ...
- POJ 2367:Genealogical tree(拓扑排序模板)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7285 Accepted: 4704 ...
- CODEFORCES 340 XOR and Favorite Number 莫队模板题
原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...
- BZOJ 1031 [JSOI2007]字符加密Cipher | 后缀数组模板题
BZOJ 1031 [JSOI2007]字符加密Cipher | 后缀数组模板题 将字符串复制一遍接在原串后面,然后后缀排序即可. #include <cmath> #include &l ...
- 在洛谷3369 Treap模板题 中发现的Splay详解
本题的Splay写法(无指针Splay超详细) 前言 首先来讲...终于调出来了55555...调了整整3天..... 看到大部分大佬都是用指针来实现的Splay.小的只是按照Splay的核心思想和原 ...
- HDU 1285 确定比赛名次(拓扑排序模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 题目大意:有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行 ...
随机推荐
- SQL Server创建LinkServer
USE [master] GO /****** Object: LinkedServer [xxx_LNK] Script Date: 2014/7/7 17:04:13 ******/ EXEC m ...
- css案例学习之层叠样式
代码 <html> <head> <title>层叠特性</title> <style type="text/css"> ...
- 不要在公共接口中传递STL容器
最近的一个项目,是开发一个framework,提供给公司内部不同的产品线使用. 之间遇到的一个问题,就是STL容器的使用, 而结论是不要在公共接口中传递STL容器: 这里说的STL容器,但主要则是指容 ...
- Linux--根文件系统的挂载过程分析
前言: 本篇文章以S3C6410公版的Linux BSP和U-Boot来进行分析,文中全部提及的名词和数据都是以该环境为例,全部的代码流程也是以该环境为例来进行分析.哈哈.假设有不对或者不完好的地方, ...
- IOS 8弃用api
IOS 8弃用api 下面api是弃用: 的 UIApplication 方法和属性注冊通知. 使用新的API. 的 uiviewcontroller 面向接口的方法和属性. 中描写叙述的特征和大小类 ...
- leetcode之 median of two sorted arrays
这是我做的第二个leetcode题目,一开始以为和第一个一样很简单,但是做的过程中才发现这个题目非常难,给人一种“刚上战场就踩上地雷挂掉了”的感觉.后来搜了一下leetcode的难度分布表(leetc ...
- 设置dialog显示,自定义时间到后dialog消失
方法一: public class MyDialog extends Dialog { private int FLAG_DISMISS = 1; private boolean flag = tru ...
- T-SQL开窗函数
开窗函数over() 用途一:排序order by ,row_number select *,RANK() over(order by english desc) from Score --根据英语成 ...
- sqlserver查询某一字段重复超5次的所有记录
用的sqlserver2008 r2. SELECT * FROM t_class WHERE id IN (SELECT id FROM (SELECT ROW_NUMBER() OVER ( ...
- javascript实现倒计时
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...