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

快排7032MS水过

Posted by donkeyinacm at 2010-03-08 20:27:02 on Problem 2104
#include <iostream>
#include <algorithm>
using namespace std;
#define MAXN 100005
struct data
{
	int pos,val;
};
data N[MAXN];
int cmp(const void *a,const void *b)
{
	return static_cast<const data*>(a)->val-static_cast<const data*>(b)->val;
}

int main()
{
	//freopen("c:/aaa.txt","r",stdin);
	int i,p,a,b,k,cnt,n,m;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&N[i].val);
		N[i].pos=i;
	}
	qsort(N+1,n,sizeof(N[0]),cmp);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&k);
		cnt=0;
		for(p=1;p<=n;p++)
			if(a<=N[p].pos&&N[p].pos<=b)
			{
				cnt++;
				if(cnt==k)
					break;
			}
			printf("%d\n",N[p].val);
	}
	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