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

麻烦大家帮我找一找错误,一直wa,我检查了很久都没有结果,先谢谢了!!!

Posted by sunnyboy1001 at 2008-04-29 16:25:02 on Problem 2736
#include<stdio.h>
#include<math.h>
int f(int w,int x,int y,int z);
int main(void)
{
   int num,i,a[1010][6],ans,l,w,j,zu=1,d;
   while(1){
      ans=0;
      scanf("%d",&num);
      if(num==0)
         break;
      for(i=0;i<num;i++){
         scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i][2],&a[i][3]);
         a[i][4]=(int)fabs(a[i][0]-a[i][2]);
         a[i][5]=(int)fabs(a[i][1]-a[i][3]);
         for(l=a[i][4],w=a[i][5];l>0&&w>0;l--,w--)
            ans+=l*w;
      }   
      for(i=0;i<num-1;i++)
         for(j=i+1;j<num;j++){
            if(a[i][0]==a[j][0]||a[i][0]==a[j][2]||a[i][2]==a[j][0]||a[i][2]==a[j][2]){
               d=f(a[i][1],a[i][3],a[j][1],a[j][3])-2;
               for(w=d-1,l=2;l<=a[i][4]+a[j][4]&&w>0;w--,l++){
                  if(l<=a[i][4]+1&&l<=a[j][4]+1)
                     ans+=w*(l-1);
                  else if(l>a[i][4]+1&&l>a[j][4]+1)
                     ans+=w*(a[i][4]+a[j][4]-l+1);
                  else{
                     if(l>a[i][4]+1){
                        ans+=w*a[i][4];
                     }   
                     else{
                        ans+=w*a[j][4];
                     }   
                  }   
               }   
            }   
            if(a[i][1]==a[j][1]||a[i][1]==a[j][3]||a[i][3]==a[j][1]||a[i][3]==a[j][3]){
               d=f(a[i][0],a[i][2],a[j][0],a[j][2])-2;
               for(w=d-1,l=2;l<=a[i][5]+a[j][5]&&w>0;w--,l++){
                  if(l<=a[i][5]+1&&l<=a[j][5]+1)
                     ans+=w*(l-1);
                  else if(l>a[i][5]+1&&l>a[j][5]+1)
                     ans+=w*(a[i][5]+a[j][5]-l+1);
                  else{
                     if(l>a[i][5]+1){
                        ans+=w*a[i][5];
                     }   
                     else{
                        ans+=w*a[j][5];
                     }   
                  }   
               }   
            }   
         }
      printf("Case %d: %d\n",zu++,ans);
   }   
   system("pause");
   return 0;
}    
int f(int w,int x,int y,int z)
{
   int hold;
   if(w>x){
      hold=w;
      w=x;
      x=hold;
   }   
   if(y>z){
      hold=y;
      y=z;
      z=hold;
   }   
   if(z>x)
      hold=x;
   else
      hold=z;
   if(y>w)
      hold-=y;
   else
      hold-=w;
   return hold;
}   

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