Poj 2371--Questions and answers(QSort)
来源:互联网 发布:cms下载 编辑:程序博客网 时间:2024/06/05 22:59
题目:http://poj.org/problem?id=2371
题意:先输入N个数,再输入K个数,问这K个数Ki,问N个数中第Ki个数是什么;
思路:先排序,好久没写快排了,复习复习
源代码:(47MS)
#include<iostream>using namespace std;const int MAX_N=100005;int a[MAX_N];int n;int Partition(int low,int high){int key=a[low];while(low<high){while(low<high && a[high]>=key)high--;a[low]=a[high];while(low<high && a[low]<=key)low++;a[high]=a[low];}a[low]=key;return low;}void QSort(int low,int high){if(low<high){int pivotloc = Partition(low,high);QSort(low,pivotloc-1);QSort(pivotloc+1,high);}}int main(){int i,j,k;cin>>n;for(i=1;i<=n;i++)scanf("%d",&a[i]);char symbol[5];cin>>symbol;QSort(1,n);cin>>k;for(i=0;i<k;i++){cin>>j;cout<<a[j]<<endl;}return 0;}
- Poj 2371--Questions and answers(QSort)
- POJ 2371 Questions and answers(水~)
- poj 2371 Questions and answers
- poj 2371 Questions and answers
- POJ 2371 Questions and answers
- poj 2371 Questions and answers
- POJ 一 2371 Questions and answers
- POJ2371:Questions and answers
- POJ_2371 Questions and answers
- hdu Questions and answers
- BNU Questions and answers
- google questions and answers
- google questions and answers
- URAL 1026. Questions and answers
- gSOAP toolkit questions and answers
- .NET Interview Questions And Answers
- ural 1026 Questions and Answers
- Tibco designer questions and answers
- PhoneGap架构基础及工作原理调研报告
- 两指针减法的prtdiff_t类型
- java.util.date , java.sql.date , java.sql.timestamp
- sqlserver2005连接出错解决方案
- POJ-4039(编译原理)(Guess the Numbers)
- Poj 2371--Questions and answers(QSort)
- DataGridComboBoxColumn为什么就不能在Binding的时候引用其他Named Element了呢?
- 用java调用oracle存储过程总结
- Redis配置文件分析
- Web.py Cookbook 简体中文版
- USACO 4.2 The Perfect Stall网络流解最大二分图匹配
- 自动化测试框架的搭建
- 对字符数组,字符指针,字符串常量以及其sizeof的一些总结
- JSTL标签用法