心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
The solution is to sort.Quick sort will be okay.
And pay attention to the string of three symbols "#".
Here is my code:
#include<iostream>
#define maxn 100007
using namespace std;
long n,k,r[maxn];
void Qsort(long *a,long l,long r)
{
    
long i=l,j=r,mid=a[(l+r)/2];
    
do{
        
while(a[i]<mid) i++;
        
while(a[j]>mid) j--;
        
if(i<=j)
        {
            
long t=a[i];a[i]=a[j];a[j]=t;
            i
++;j--;
        }
    }
while(i<=j);
    
if(l<j) Qsort(a,l,j);
    
if(i<r) Qsort(a,i,r);
}
int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    cin
>>n;
    
for(long i=1;i<=n;i++)
        cin
>>r[i];
    Qsort(r,
1,n);
    getchar();getchar();getchar();getchar();getchar();
    cin
>>k;
    
for(long i=1;i<=k;i++)
    {
        
long t;
        cin
>>t;
        cout
<<r[t]<<endl;
    }
return 0;
}


posted on 2010-09-25 21:16 lee1r 阅读(119) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:基础/模拟

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理