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 怀疑是读入数据时的问题,我把intersect全部return 1 了还是tle ,帮忙看看/*pku 2653 Pick-up sticks 051221 */ #include<stdio.h> #define N 100000 typedef struct line{ float x1,x2,y1,y2; long flag; }LINE; int intersect(LINE* l1,LINE* l2) { float dx,dy; if( (l1->x1>l2->x2) || (l1->y1>l2->y2) || (l2->x1>l1->x2) || (l2->y1>l1->y2) ) return 0; dx=l1->x1-l1->x2,dy=l1->y1-l1->y2; if( (dx*(l2->y1-l1->y1)-dy*(l2->x1-l1->x1) )* (dx*(l2->y2-l1->y1)-dy*(l2->x2-l1->x1) )>0 ) return 0; dx=l2->x1-l2->x2,dy=l2->y1-l2->y2; if( (dx*(l1->y1-l2->y1)-dy*(l1->x1-l2->x1) )* (dx*(l1->y2-l2->y1)-dy*(l1->x2-l2->x1) )>0 ) return 0; return 1; } LINE top[N]; int main() { float x11,y11,x21,y21; long sticks,ii,jj; for(;scanf("%ld",&sticks);) { if(!sticks) return; for(jj=0;jj<sticks;jj++) { top[jj].flag=jj+1; scanf("%f%f%f%f",&x11,&y11,&x21,&y21); (top[jj].x1)=(x11>x21)?x21:x11, (top[jj].y1)=(y11>y21)?y21:y11, (top[jj].x2)=(x11<x21)?x21:x11, (top[jj].y2)=(y11<y21)?y21:y11; for(ii=0;ii<jj;ii++) if(top[ii].flag&&intersect(&top[ii],&top[jj])) { top[ii].flag=0; } } printf("Top sticks: "); for(jj=0;!(top[jj].flag);jj++) ; printf("%ld",top[jj].flag); for(jj++;jj<sticks;jj++) if(top[jj].flag) printf(", %ld",top[jj].flag); printf(".\n"); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator