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 <iostream> #include <cstdio> #include <algorithm> using namespace std; const int MAX=25005; struct node { int x; int y; }data[MAX]; int cmp(node a,node b) { if(a.x==b.x) return a.y>b.y; else return a.x<b.x; } int main() { int N,T; scanf("%d%d",&N,&T); for(int i=0;i<N;i++) scanf("%d%d",&data[i].x,&data[i].y); sort(data,data+N,cmp); int loc=0; int index=0; int count=0; int max_right=0; bool flag=false; if(data[0].x!=1) { printf("-1\n"); return 0; } while(loc<T && index<N) { int i; for(i=index;i<N;i++) { if(data[i].x<=loc+1) { if(data[i].y>max_right && data[i].y>loc) { flag=true; // printf("%d %d\n",data[i].x,data[i].y); max_right=data[i].y; } } else break; } if(flag) { count++; loc=max_right; flag=false; } if(data[i].y<=loc) index++; } if(loc<T) printf("-1\n"); else printf("%d\n",count); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator