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

Re:都做到这个份上了,怎么还超时

Posted by lijingwei at 2010-08-06 09:03:07 on Problem 2104 and last updated at 2010-08-06 09:06:15
In Reply To:牛人看下为何超时!!!!!!!! Posted by:lijingwei at 2010-07-04 11:21:39
#include<iostream>
#include<algorithm>
using namespace std;
struct In
{    
	int x; 
	int id;
}s[100015]; 
int cmp(const void *a , const void *b)
{
	struct In *c=(In *)a;
	struct In *d = (In *)b;  
	return c->x-d->x;
}
int main()
{
    int m,n;
    int a,b,c,i; 
	cin>>n>>m; 
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i].x);  
		s[i].id=i;
	} 
	qsort(s,n,sizeof(s[0]),cmp);//只用作一次快排,而不是m次
	while(m--)
	{
		scanf("%d%d%d",&a,&b,&c);  
		for(i=0;i<n;i++) 
		{
			if(s[i].id>=a-1&&s[i].id<=b-1)
				c--;
			if(c==0)//数到0,则找到该数   
				break;  
          } 
		printf("%d\n",s[i].x); 
       }
	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