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

莫名其妙的错,谁能找出来?

Posted by fmlwlh at 2007-07-18 13:42:46 on Problem 3269
我不喜欢贴代码,但这个错误太经典了,经典得我虽然知道哪错,却不知道为什么,哪位大牛能告诉我?
#include<iostream>
#include<algorithm>
#include<cmath>
#define abs(a) ((a)>0?(a):(-a))
using namespace std;
typedef struct point{
        int x,y;
        }point;
point p[10010];
int N,x[10010],y[10010];
int exsit(int x1,int y1)
{
    int i;
    for (i=0;i<N;i++) if (p[i].x==x1&&p[i].y==y1) break;
    if (i<N) return 1;
    return 0;
}
__int64 dis(int x1,int y1)
{
    int i,j;
    __int64 ans=0;
    for (i=0;i<N;i++) 
    {
        ans+=(__int64)abs(x[i]-x1);
        ans+=(__int64)abs(y[i]-y1);
    }
    return ans;
}
main ()
{
     int i,j,spot;
     __int64 barn=0;
     
     
     scanf ("%d",&N);
     for (i=0;i<N;i++) 
     {
         scanf ("%d %d",&x[i],&y[i]);
         p[i].x=x[i];
         p[i].y=y[i];
     }
     sort(x,x+N);
     sort(y,y+N);
     for (i=(N-1)/2;i>=0;i--) 
     {
         barn+=(__int64)(x[N-1-i]-x[i]); 
         barn+=(__int64)(y[N-1-i]-y[i]);
     }
     if (N&1)
     {
         if (exsit(x[N/2],y[N/2])==0) printf("%I64d 1\n",barn); 
         else 
         {
              barn=1<<30;
              __int64 temp=dis(x[N/2]-1,y[N/2]);
              if (temp<barn) {barn=temp;spot=1;}
              else if (temp==barn) spot++;
              
              temp=dis(x[N/2]+1,y[N/2]);
              if (temp<barn) {barn=temp;spot=1;}
              else if (temp==barn) spot++;
              
              temp=dis(x[N/2],y[N/2]-1);
              if (temp<barn) {barn=temp;spot=1;}
              else if (temp==barn) spot++;
              
              temp=dis(x[N/2],y[N/2]+1);
              if (temp<barn) {barn=temp;spot=1;}
              else if (temp==barn) spot++;
              printf ("%I64d %d\n",barn,spot);
         }
     }
     else
     {
         spot=(x[N/2]-x[N/2-1]+1)*(y[N/2]-y[N/2-1]+1);
         if (exsit(x[N/2-1],y[N/2-1])) spot--;
         if (exsit(x[N/2-1],y[N/2])) spot--;  
         if (exsit(x[N/2],y[N/2-1])) spot--;
         if (exsit(x[N/2],y[N/2])) spot--; 
         printf("%I64d %d\n",barn,spot);
     }
              
     system("pause");
     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