| ||||||||||
| 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>
#define MAXN 1010
struct {int x1,x2,y1,y2;} p[MAXN];
int n,area;
void cover(int a,int b,int c,int d,int i)
{
if(i<=n&&(a>=p[i].x2||b>=p[i].y2||c<=p[i].x1||d<=p[i].y1))
i++;
if(i>n) {area+=(c-a)*(d-b);return;}
if(a<p[i].x1) {cover(a,b,p[i].x1,d,i+1);a=p[i].x1;}
if(b<p[i].y1) {cover(a,b,c,p[i].y1,i+1);b=p[i].y1;}
if(c>p[i].x2) {cover(p[i].x2,b,c,d,i+1);c=p[i].x2;}
if(d>p[i].y2) {cover(a,p[i].y2,c,d,i+1);d=p[i].y2;}
}
int main()
{
int i;
while(1)
{
for(i=1;;i++)
{
scanf("%d %d %d %d",&p[i].x1,&p[i].y1,&p[i].x2,&p[i].y2);
if(p[i].x1+p[i].y1+p[i].x2+p[i].y2<0) break;
}
if(i==1) break;
area=0;
for(n=--i;i;i--)
cover(p[i].x1,p[i].y1,p[i].x2,p[i].y2,i+1);
printf("%d\n",area);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator