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

已经这么简单的程序应该怎么改进,才能不超时?

Posted by 00348264 at 2005-01-15 18:11:51 on Problem 2104
#include<stdio.h>
#include<stdlib.h>
long rec[100001],*temp[100001];
int comp(const void* p1,const void* p2)
{
	return **(long**)p1-**(long**)p2;
}
int main()
{
	
	long n,m,i1,i2,i3,i4;
	scanf("%d%d",&n,&m);
	for(i1=1;i1<=n;i1++)
		scanf("%d",&rec[i1]);
	long i,j,k,size=sizeof(temp[1]);
	for(i2=1;i2<=m;i2++)
	{
		scanf("%d%d%d",&i,&j,&k);		
		for(i3=i,i4=1;i3<=j;i3++,i4++)
			temp[i4]=&rec[i3];		
		qsort(&temp[1],j-i+1,size,comp);
		printf("%d\n",*temp[k]);		
	}
	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