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

大虾们,帮我看看,怎么解决TLE 感谢了!!!!!!!!!

Posted by 766826825 at 2010-08-19 11:27:16 on Problem 1456
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct aaaa
{ 
	int x; 
	int y; 

}In;
In s[10050]; 

int cmp( const void *a , const void *b ) 
{ 
	In *c = (In *)a; 
	In *d = (In *)b; 
	if(c->y != d->y) return c->y - d->y; 
	else return d->x - c->x; 
} 
int main()
{   
	int m,sum=0;
	int n;
	while(1)
	{
		scanf("%d",&m);
		memset(s,0,10050*sizeof(In));
				for(n=0;n<m;n++)
			scanf("%d%d",&s[n].x,&s[n].y);
		qsort(s,m,sizeof(s[0]),cmp); 
		sum=s[0].x;
		for(n=1;n<m;n++)
		{
			if(s[n].y!=s[n+1].y)
				sum+=s[n+1].x;
		}
		printf("%d\n",sum);
		sum=0;
	}
	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