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*5 *_*

Posted by noskill at 2005-04-28 23:04:44 on Problem 2036
#include<stdio.h>
#include<math.h>
double k[10001],x[10001],y[10001];
const int maxk=100020;
struct btreenode{
  double data;
  double x,y;
  btreenode *left;
  btreenode *right;
};
bool findbstreen(btreenode *bst,double &item,double &xn,double &yn)
{
  while(bst!=NULL){
    if(fabs(item-bst->data)<0.000000001)
    {
        if(item==maxk||fabs(yn-bst->y)<0.00000000001||fabs((yn-bst->y)/(xn-bst->x)-item)<0.000000001)return 1;
        else bst=bst->right;
    }    
    else if(item<bst->data)bst=bst->left;
    else bst=bst->right;
  }
  return 0;
}
void insertbstreen(btreenode *&bst,const double &item,double &xn,double &yn)
{
  btreenode *t=bst,*parent=NULL;
  while(t!=NULL){
    parent=t;
    if(item<t->data)t=t->left;
    else t=t->right;
  }
  btreenode *p=new btreenode;
  p->data=item;p->x=xn;p->y=yn;
  p->left=p->right=NULL;
  if(parent==NULL)bst=p;
  else if(item<parent->data)parent->left=p;
       else parent->right=p;
}

int main()
{
    int i,j,kn,dn;
    double x1,y1,x2,y2,kt,xt,yt;
    btreenode *b=NULL;
    while(scanf("%d",&dn),dn)
    {
        kn=0;b=NULL;
        for(i=0;i<dn;i++)
        {
            scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
            if(x1-x2!=0)kt=(y1-y2)/(x1-x2);else kt=maxk;
            if(findbstreen(b,kt,x1,y1))continue;
            insertbstreen(b,kt,x1,y1); kn++;
        }    
        printf("%d\n",kn);
    }
    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