POJ 1375 Intervals G++ 几何 背

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
//英语      看博友分析有图      抄博友程序       几何        背 
struct point{
	double x;
	double y;
};
struct nod{
	double l;
	double r;
};
double dis(point a, point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(nod a,nod b)
{
	return a.l<b.l;
}
int main()
{
	while(1)
	{
		int n;
		//cin>>n;
		scanf("%d",&n);
		if(n==0)
		{
			break;
		}
		point p;
		//cin>>p.x>>p.y;
		scanf("%lf%lf",&p.x,&p.y);
		vector<nod> ve;
		for(int i=0;i<n;i++)
		{
			double r;
			point q;
			//cin>>q.x>>q.y>>r;
			scanf("%lf%lf%lf",&q.x,&q.y,&r);
			double d=dis(p,q);
			double a=asin(r/d);
			double b=asin((p.x-q.x)/d); 
			double j1=a+b;
			double j2=b-a;
			nod t;
			t.l=p.x-tan(j1)*p.y;
			t.r=p.x-tan(j2)*p.y;
			ve.push_back(t);
		}
		sort(ve.begin(),ve.end(),cmp);
		double L=ve[0].l;
		double R=ve[0].r;
		for(int i=1;i<n;i++)
		{
			if(ve[i].l>R)
			{
				cout<<fixed<<setprecision(2)<<L<<" "<<R<<endl;
				L=ve[i].l;
				R=ve[i].r;
			}else
			{
				R=max(R,ve[i].r);
			}
		}	
		cout<<fixed<<setprecision(2)<<L<<" "<<R<<endl<<endl;	
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值