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=;
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=;
while(scanf("%d",&n)!=EOF&&n){
if(flag)putchar('\n');
flag=;
cnt=;
scanf("%lf%lf",&st.x,&st.y);
for(int i=;i<=n;i++){
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
tangent(p[i],st);
}
sort(ans+,ans+cnt+,cmp);
dl L=ans[].l,R=ans[].r;
for(int i=;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 ;
}

POJ1375:Intervals——题解的更多相关文章

  1. POJ1375 Intervals

    嘟嘟嘟 题意简述:给出一个光源\((x_0, y_0)\),和一些圆,求投影区间. 这道题其实就是求经过\((x_0, y_0)\))的圆的切线. 刚开始我想到了一个用向量旋转的方法,但是写起来特别麻 ...

  2. 【LeetCode】Merge Intervals 题解 利用Comparator进行排序

    题目链接Merge Intervals /** * Definition for an interval. * public class Interval { * int start; * int e ...

  3. HDOJ1384 Intervals 题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1384 大意:有 \(n\) 个区间 \([a_i,b_i]\),每个区间有个权值 \(c_i\),找到 ...

  4. [Leetcode Week2]Merge Intervals

    Merge Intervals题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/merge-intervals/description/ Descript ...

  5. 算法与数据结构基础 - 排序(Sort)

    排序基础 排序方法分两大类,一类是比较排序,快速排序(Quick Sort).归并排序(Merge Sort).插入排序(Insertion Sort).选择排序(Selection Sort).希尔 ...

  6. 算法与数据结构基础 - 贪心(Greedy)

    贪心基础 贪心(Greedy)常用于解决最优问题,以期通过某种策略获得一系列局部最优解.从而求得整体最优解. 贪心从局部最优角度考虑,只适用于具备无后效性的问题,即某个状态以前的过程不影响以后的状态. ...

  7. [LeetCode]题解(python):056-Merge Intervals

    题目来源 https://leetcode.com/problems/merge-intervals/ Given a collection of intervals, merge all overl ...

  8. 【题解】【区间】【二分查找】【Leetcode】Insert Interval & Merge Intervals

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  9. LeetCode 题解 56. Merge Intervals

    题目大意:给出一组区间,合并他们. 首先是排序,首先看start,start小的在前面.start相同的话,end小的在前面. 排序以后,要合并了. 我自己的笨方法,说实在的问题真的很多.提交了好几次 ...

随机推荐

  1. linux进程的学习笔记(未完)

    1. 进程是程序执行的一个实例,如果16个用户同时运行vi,那么有16个独立的进程,尽管它们共享同一个可执行代码,问题在于FreeRTOS这种系统,是否可以建2个相同的任务,需要注意什么?在linux ...

  2. TPO-15 C1 The campus newspaper's reporter position

    TPO-15 C1 The campus newspaper's reporter position 第 1 段 1.Listen to a conversation between a Studen ...

  3. 前端开发工程师 - 01.页面制作 - 第3章.HTML

    第3章--HTML HTML简介 Hyper Text Markup Language:超文本标记语言--用于标记网页的内容 history: html(1991)雏形 -> html4.01( ...

  4. labview--http协议数据交互

    最近接了一个项目,需求是要将采集到的数据,以以下要求上报,并且提供接口供上层系统下发指令. 采用restful的http协议进行交互: 输入输出参数皆为json体. 响应包含三部分: Code:业务码 ...

  5. C 计算数字的位数循环

    #include <stdio.h> int main(int argc, char **argv) { // int x; int n=0; scanf("%d",& ...

  6. (python)leetcode刷题笔记 02 Add Two Numbers

    2. Add Two Numbers You are given two non-empty linked lists representing two non-negative integers. ...

  7. pthon web框架flask(一)

    pthon web框架优劣: 知乎上有一个讨论Python 有哪些好的 Web 框架?,从这个讨论中最后我选择了flask,原因是: Django,流行但是笨重,还麻烦,人生苦短,肯定不选 web.p ...

  8. linux服务器操作小技巧

    python程序后台一直运行,并将打印信息输出到文件中 nohup -u test.py > out.txt & -u 表示无缓冲,直接将打印信息输出带文件中 &表示程序后台运行

  9. 查找当前对象中的方法对象的属性叫做_event_name的方法

    setattr( self, '_events', {e._event_name: e for _, e in getmembers(self, lambda x: ismethod(x) and h ...

  10. Zen Coding && Emmet-Sublime 安装

    Sublime Text 插件之:Emmet,旧版称:ex-Zen Coding 更名之后增加了CSS3和HTML5许多新特性.项目地址也从 code.google 移 github. 安装: Pac ...