Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
已经这么简单的程序应该怎么改进,才能不超时?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator