POJ1375:Intervals——题解

http://poj.org/problem?id=1375

题目大意:有一盏灯,求每段被圆的投影所覆盖的区间。

——————————————————————

神题,卡精度,尝试用各种方法绕过精度都不行……会了之后直接抄代码吧……

求切线和卡精度秘制写法请参考这个博客:http://blog.csdn.net/acm_cxlove/article/details/7896110、

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const int N=501;
const dl eps=0.000001;
struct point{
    dl x;
    dl y;
    dl r;
}p[N],st;
struct line{
    dl l;
    dl r;
}ans[N];
int n,cnt;
bool cmp(line a,line b){
    return a.l<b.l;
}
inline dl dis(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
inline void tangent(point a,point s){
    dl l=dis(s,a);
    dl m=asin(a.r/l);
    dl n=asin((s.x-a.x)/l);
    line k;
    k.l=s.x-s.y*tan(m+n);  
    k.r=s.x-s.y*tan(n-m);
    ans[++cnt]=k;
    return;
}
int main(){
    bool flag=0;
    while(scanf("%d",&n)!=EOF&&n){
    if(flag)putchar('\n');
    flag=1;
    cnt=0;
    scanf("%lf%lf",&st.x,&st.y);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
        tangent(p[i],st);
    }
    sort(ans+1,ans+cnt+1,cmp);
    dl L=ans[1].l,R=ans[1].r;
    for(int i=2;i<=cnt;i++){
        if(ans[i].l>R){
        printf("%.2f %.2f\n",L,R);
        L=ans[i].l;R=ans[i].r;
        }else{
        R=max(R,ans[i].r);
        }
    }
    printf("%.2f %.2f\n",L,R);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/luyouqi233/p/8074375.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值