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

为什么我G++能过 C++就不能过呢 这是什么原因 请大牛说说可能的原因 代码附上

Posted by qdbis at 2008-09-12 15:19:02 on Problem 1375
#include <iostream>
#include <math.h>
using namespace std;

#define MAX_S 500
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)

struct Pipe
{
 double x;
 double y;
 double r;
};

bool judge(Pipe & p1,Pipe & p2)
{
 double x,y;
 x=max(p1.x,p2.x);
 y=min(p1.y,p2.y);
 if(x>y)return false;
 p2.x=min(p1.x,p2.x);
 p2.y=max(p1.y,p2.y);
 return true;
}


Pipe pipe[MAX_S];
Pipe result[MAX_S];

double myx,myy;

int cmp(const void * a,const void * b)
{
	Pipe * A=(Pipe *)a;
	Pipe * B=(Pipe *)b;
	if(A->x<B->x)return -1;
	return 1;
}

#define EPS 1e-10

void fun(Pipe & p)
{

	double d,cta,l;
	double k,k1,k2;
	
		d=sqrt((myx-p.x)*(myx-p.x)+(myy-p.y)*(myy-p.y));
		cta=asin(p.r/d);
		if(fabs(p.x-myx)<=EPS)//圆心坐标与光源坐标相同//
		{
			l=myy*tan(cta);
			p.x=myx-l,p.y=myx+l;
		}
		else if(fabs(p.x+p.r-myx)<=EPS)
        {
		l=myy*tan(2*cta);
		p.x=myx-l;
		p.y=myx;
		}
		else if(fabs(p.x-p.r-myx)<=EPS)
        {
		l=myy*tan(2*cta);
		p.x=myx;
		p.y=myx+l;
		}
		else
        {
			k=(myy-p.y)/(myx-p.x);
			k1=(k-tan(cta))/(1+k*tan(cta));
			k2=(k+tan(cta))/(1-k*tan(cta));
			p.x=myx-myy/k1;
			p.y=myx-myy/k2;
		}        
	
}


int main()
{
 //freopen("in.txt","r",stdin);

 int n,i,j,k;
 while(1)
 {
  scanf("%d%lf%lf",&n,&myx,&myy);
  if(n==0)break;
  for(i=0;i<n;i++)
  {
   scanf("%lf%lf%lf",&pipe[i].x,&pipe[i].y,&pipe[i].r);
   fun(pipe[i]);
  }
  
  int queue[MAX_S];
  int pf=0;

  for(i=0;i<n-1;i++)
  {
   for(j=i+1;j<n;j++)
   {
    if(judge(pipe[i],pipe[j]))break;
   }
   if(j==n)queue[pf++]=i;
  }
  
  queue[pf++]=n-1;
  for(i=0;i<pf;i++)
  {
   result[i]=pipe[queue[i]];
  }
  qsort(result,pf,sizeof(Pipe),cmp);
  for(i=0;i<pf;i++)
  {
   printf("%0.2lf %0.2lf\n",result[i].x,result[i].y);
  }
  printf("\n");

 }
 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