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

why re

Posted by veness at 2005-01-09 15:41:17 on Problem 2104
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
int z,d[110001],a[110001];
void quickSort(int l,int r)
{
	if (l >= r || z<=0) return;
	int i = l,j = r + 1,pivot = d[l],tm;
	while(1)
	{
		do {++i;} while (d[i] < pivot);
		do {--j;} while (d[j] > pivot);
		if (i >= j) break;
		tm = d[i];
		d[i] = d[j];
		d[j] = tm;
	}
	d[l] = d[j];
	d[j] = pivot;
	tm = j-l;
	if(tm>=z)
		quickSort(l, j-1);
	else
	{
		z -= tm+1;
		quickSort(j+1, r);
	}
}
void main()
{
	long x,y,i,n,m;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;++i)
		scanf("%d",&a[i]);
    while(m--)
    {
		scanf("%d%d%d",&x,&y,&z);
		--x,y-=x;
		memcpy(d,a+x,(y<<4));
		--y;
		i = z-1;
		quickSort(0,y);
		printf("%d\n",d[i]);
	}
}

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