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 |
wa了数十次用时8小时终于a了悲剧啊#include<stdio.h> #include<stdlib.h> #define MAX 25000+10 struct node { int x,y; }v[MAX]; int cmp(const void *_a,const void *_b) { node *a=(node *)_a; node *b=(node *)_b; if((a->x) != (b->x)) return a->x - b->x; else return b->y - a->y; } int main() { int n,t; int s,e,max; int flag,mark; int cnt; while(scanf("%d %d",&n,&t)>0) { for(int i=0;i<n;i++) { scanf("%d %d",&v[i].x,&v[i].y); } qsort(v,n,sizeof(v[0]),cmp); if(v[0].x!=1) { printf("-1\n"); continue; } if(v[0].x==1&&v[0].y==t){printf("1\n"); continue;} int i=0; s=e=max=0; mark=0; cnt=0; while(i<n) { flag=0; while(v[i].x<=e+1&&i<n) { if(v[i].y<=max) { i++; continue; } else { max=v[i].y; flag=1; } } if(flag) { e=max; cnt++; } else { break; } if(max==t) { mark=1; break; } } if(mark) printf("%d\n",cnt); else printf("-1\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator