Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

有比这更水的吗?NO!

Posted by 2010302535 at 2012-07-11 11:12:13 on Problem 2371
//上面排个序,下面输出
#include <iostream>
using namespace std;

void Swap(int *a,int i,int j)
{
	int x;
	x=a[i];a[i]=a[j];a[j]=x;
}

int partition(int p,int r,int *a)
{
	int i=p,j=r+1;
	int x=a[p];
	while(true)
	{
		while(a[++i]<x&&i<r);
		while(a[--j]>x);
		if(i>=j)
			break;
		Swap(a,i,j);
	}
	a[p]=a[j];
	a[j]=x;
	return j;
}

void qSort(int p,int r,int *a)
{
	if(p<r)
	{
		int q=partition(p,r,a);
		qSort(p,q-1,a);
		qSort(q+1,r,a);
	}
}

int main()
{
	char a[4];
	int s[150000],i,n,b[5000];
	cin >> n;
	for(i=0;i<n;i++)
		cin >> s[i];
	qSort(0,n-1,s);
	cin >> a;
	cin >> n;
	while(n--)
	{
		cin >> i;
		cout << s[i-1] << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator