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 |
大虾们,帮我看看,怎么解决TLE 感谢了!!!!!!!!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator