UVA 313 Intervals

点击打开链接

这题got WA again again and again

求指教

 

//大白p263
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const double eps=1e-8;//精度
const int INF=1<<29;
const double PI=acos(-1.0);
int dcmp(double x){//判断double等于0或。。。
    if(fabs(x)<eps)return 0;else return x<0?-1:1;
}
struct Point{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}
};
typedef Point Vector;
typedef vector<Point> Polygon;
Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}//向量+向量=向量
Vector operator-(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}//点-点=向量
Vector operator*(Vector a,double p){return Vector(a.x*p,a.y*p);}//向量*实数=向量
Vector operator/(Vector a,double p){return Vector(a.x/p,a.y/p);}//向量/实数=向量
bool operator<( const Point& A,const Point& B ){return dcmp(A.x-B.x)<0||(dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)<0);}
bool operator==(const Point&a,const Point&b){return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;}
bool operator!=(const Point&a,const Point&b){return a==b?false:true;}
struct Segment{
    Point a,b;
    Segment(){}
    Segment(Point _a,Point _b){a=_a,b=_b;}
    bool friend operator<(const Segment& p,const Segment& q){return p.a<q.a||(p.a==q.a&&p.b<q.b);}
    bool friend operator==(const Segment& p,const Segment& q){return (p.a==q.a&&p.b==q.b)||(p.a==q.b&&p.b==q.a);}
};
struct Circle{
    Point c;
    double r;
    Circle(){}
    Circle(Point _c, double _r):c(_c),r(_r) {}
    Point point(double a)const{return Point(c.x+cos(a)*r,c.y+sin(a)*r);}
    bool friend operator<(const Circle& a,const Circle& b){return a.r<b.r;}
};
struct Line{
    Point p;
    Vector v;
    double ang;
    Line() {}
    Line(const Point &_p, const Vector &_v):p(_p),v(_v){ang = atan2(v.y, v.x);}
    bool operator<(const Line &L)const{return  ang < L.ang;}
};
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}//|a|*|b|*cosθ 点积
double Length(Vector a){return sqrt(Dot(a,a));}//|a| 向量长度
double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}//向量夹角θ
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}//叉积 向量围成的平行四边形的面积
double Area2(Point a,Point b,Point c){return Cross(b-a,c-a);}//同上 参数为三个点
double DegreeToRadius(double deg){return deg/180*PI;}
double GetRerotateAngle(Vector a,Vector b){//向量a顺时针旋转theta度得到向量b的方向
    double tempa=Angle(a,Vector(1,0));
    if(a.y<0) tempa=2*PI-tempa;
    double tempb=Angle(b,Vector(1,0));
    if(b.y<0) tempb=2*PI-tempb;
    if((tempa-tempb)>0) return tempa-tempb;
    else return tempa-tempb+2*PI;
}
double torad(double deg){return deg/180*PI;}//角度化为弧度
Vector Rotate(Vector a,double rad){//向量逆时针旋转rad弧度
    return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
Vector Normal(Vector a){//计算单位法线
    double L=Length(a);
    return Vector(-a.y/L,a.x/L);
}
Point GetLineProjection(Point p,Point a,Point b){//点在直线上的投影
    Vector v=b-a;
    return a+v*(Dot(v,p-a)/Dot(v,v));
}
Point GetLineIntersection(Point p,Vector v,Point q,Vector w){//求直线交点 有唯一交点时可用
    Vector u=p-q;
    double t=Cross(w,u)/Cross(v,w);
    return p+v*t;
}
//--------------------------------------
//--------------------------------------
//--------------------------------------
//--------------------------------------
//--------------------------------------
int n;
Circle arr[505];
struct node{
	double x;
	int mark;
	friend bool operator<(node a,node b){
		return dcmp(a.x-b.x)<0;
	}
}res[2005];
int idx;
int main(){
	Line xzhou(Point(0,0),Vector(1,0));
	int cas=1;
	while(scanf("%d",&n)&&n){
		idx=0;
		Point s;
		scanf("%lf%lf",&s.x,&s.y);
		for(int i=0;i<n;i++){
			scanf("%lf%lf%lf",&arr[i].c.x,&arr[i].c.y,&arr[i].r);
			Vector v=arr[i].c-s;
			double ang=asin(arr[i].r/Length(v));
			Vector lef,righ;
			lef=Rotate(v,-ang);
			righ=Rotate(v,ang);
			Point p,q;
			p=GetLineIntersection(s,lef,xzhou.p,xzhou.v);
			q=GetLineIntersection(s,righ,xzhou.p,xzhou.v);
			res[idx].x=p.x;res[idx++].mark=1;
			res[idx].x=q.x;res[idx++].mark=-1;
		}
		sort(res,res+idx);
		if(cas++!=1) printf("\n");
		int flag=0;
		double a,b;
		for(int i=0;i<idx;i++){
			if(flag==0&&res[i].mark==1)
				printf("%.2lf ",res[i].x);
			else if(flag==1&&res[i].mark==-1)
					printf("%.2lf\n",res[i].x);
			flag+=res[i].mark;
		}
	}
	return 0;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值