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 haitao1 at 2012-03-13 18:37:42 on Problem 1039
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
const double inf=1000000000;
const double eps=1e-8;
using namespace std;
struct point {
       double x,y;
       };
point a[30];
point b[30];
int n;
double m;
double mi(double a,double b)
{
 return a>b?b:a;       
}
double ma(double a,double b)
{
 return a>b?a:b;       
}
double cross(point a,point b,point c)
{
 return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);             
}
double find(point p1,point p2)
{
  int i,j,k;
  double a0,b0,c0,a1,b1,c1;
  a0=(p1.y-p2.y)/(p1.x-p2.x);
  b0=-1;
  c0=p1.y-a0*p1.x;
  double y;
  y=(a[0].x*a0)+c0;
  if(y>a[0].y||y<b[0].y)
  return -inf;
  k=0;
  for(i=0;i<n;i++)
  {
  if(cross(a[i],p1,p2)*cross(b[i],p1,p2)<=0)
  continue;
  else
  {
   double d1=-inf,d2=-inf;
   //printf("%d\n",i);
  if(cross(a[i],p1,p2)*cross(a[i-1],p1,p2)<=0-eps)
  {
   a1=(a[i].y-a[i-1].y)/(a[i].x-a[i-1].x);
   b1=-1;
   c1=a[i].y-a1*a[i].x;
  
    d1=(b0*c1-b1*c0)/(a0*b1-a1*b0);                          
  }    
   if(cross(b[i],p1,p2)*cross(b[i-1],p1,p2)<=0)
  {
   a1=(b[i].y-b[i-1].y)/(b[i].x-b[i-1].x);
   b1=-1;
   c1=b[i].y-a1*b[i].x;
   d2=(b0*c1-b1*c0)/(a0*b1-a1*b0);   
  }
  return ma(d1,d2);
  }                  
  }
  return inf;
  
}

int main()
{
    int i,j,k;
    double x1,x2,x3,x4;
    while(scanf("%d",&n)!=EOF)
    {
     if(n==0)
     break;
     m=-inf;
     for(i=0;i<n;i++)
     {
      scanf("%lf%lf",&a[i].x,&a[i].y);
      b[i].x=a[i].x;
      b[i].y=a[i].y-1;                
     }
     if(n==2)
     {
      printf("Through all the pipe.\n");
      continue;        
     }                
     for(i=0;i<n;i++)
      for(j=i+1;j<n;j++)
      {
      x1=find(a[i],a[j]);
      x2=find(a[i],b[j]);
      x3=find(b[i],a[j]);
      x4=find(b[i],a[j]); 
     //printf("%lf %lf %lf %lf\n",x1,x2,x3,x4);                 
      if(m<ma(ma(x1,x2),ma(x3,x4)))
      {
       m=ma(ma(x1,x2),ma(x3,x4));          
      // printf("%lf\n",m);                  
      }
      }
      if(m==inf)
      printf("Through all the pipe.\n");
      else
      printf("%.2lf\n",m);        
    }
    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