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 |
这种暴力法有何问题????请教!@/* Note:Your choice is C IDE */ #include "stdio.h" #include "stdlib.h" typedef struct { int x1,y1,x2,y2; int se; int flag; }longge; longge a[20]; int cmp(const void *a,const void *b) { longge *c=(longge *)a; longge *d=(longge *)b; if(c->y1!=d->y1) return d->y1-c->y1; else return c->x1-d->x1; } int main() { int n,k,i,j; int num; //freopen("2949.txt","r",stdin); scanf("%d",&n); while(n--) { scanf("%d",&k); for(i=0;i<k;i++) a[i].flag=0;//都没上色 for(i=0;i<k;i++) scanf("%d%d%d%d%d",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2,&a[i].se); qsort(a,k,sizeof(a[0]),cmp); num=0; for(i=0;i<k;i++) { if(a[i].flag==0) { a[i].flag=1;//标志上色 num++; for(j=i+1;j<k;j++) { if(a[j].y1<=a[i].y2 && a[j].x1>=a[i].x1 && a[j].x1<=a[i].x2) a[j].flag=1;//下面同颜色的一起涂色 else break;//没有连续的下方就跳出 } } } printf("%d\n",num); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator