Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

矩形切割为什么会TLE??附代码,求解释:

Posted by 2857 at 2012-09-26 19:54:39 on Problem 1389
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator