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 0002009120708 at 2011-07-18 13:16:04 on Problem 1375
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#define max(a,b) (((a)>(b))?(a):(b))
struct QJ
{double l,r;}
qj[520];
struct QJ getqj(double x1,double y1,double x2,double y2,double r){
     struct QJ ans;
     ans.l=x2+y2*tan(atan((x2-x1)/(y1-y2))-asin(r/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
     ans.r=x2+y2*tan(atan((x2-x1)/(y1-y2))+asin(r/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
     return ans;
}
int cmp(const void *a,const void *b){
    double x1=((struct QJ *)a)->l;
    double x2=((struct QJ *)b)->l;
    if(x1-x2<1e-6&&x2-x1<1e-6)return 0;
    if(x1-x2>0)return 1;
    if(x2-x1>0)return -1;
}
int main()
{
    struct QJ q;
    int n,i,top;
    double x0,y0,x,y,r;
    while(scanf("%d",&n)&&n){
        scanf("%lf%lf",&x0,&y0);
        for(i=0;i<n;i++){
           scanf("%lf%lf%lf",&x,&y,&r);
           qj[i]=getqj(x,y,x0,y0,r);
        }
        qsort(qj,n,sizeof(qj[0]),cmp);
        for(q=qj[0],i=1,top=0;i<n;i++){
             if(q.r>qj[i].l||((q.r-qj[i].l)<1e-6 &&(qj[i].l-q.r)<1e-6))
                 q.r=max(qj[i].r,q.r);
             else{
                 qj[top++]=q;
                 q=qj[i];
             }
        }
        qj[top++]=q;
        for(i=0;i<top;i++)
         printf("%.2lf %.2lf\n",qj[i].l,qj[i].r);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