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. vim程序员加强功能

    1.折叠      1.1折叠的方式有六种           manual:以标准的vim结构定义折叠跨越的范围,类似移动命令           indent:折叠与折叠的层次,对应于文本的缩排与 ...

  2. JDK11安装后,环境变量的坑

    安装了最新的JDK11,安装完后设置环境变量,打开CMD,没生效 检查了3遍,都没发现问题,在PATH中将JAVA设置移到第一也不行 最后偶然发现,在点击如图右下的‘编辑文本’,用文本方式编辑时,发现 ...

  3. 跟浩哥学自动化测试Selenium -- 浏览器的基本操作与元素定位(3)

    浏览器的基本操作与元素定位 通过上一章学习,我们已经学会了如何设置驱动路径,如何创建浏览器对象,如何打开一个网站,接下来我们要进行一些复杂的操作比如先打开百度首页,在打开博客园,网页后退,前进等等,甚 ...

  4. Linux命令应用大词典-第16章 归档和压缩

    16.1 tar:进行归档和压缩 16.2 gzip:压缩或解压缩gzip文件 16.3 gunzip:解压缩gzip文件 16.4 zcmp:比较gzip压缩文件 16.5 zdiff:比较gzip ...

  5. Python基础 之 数据类型

    数据类型 一.运算符 算数运算a = 10 * 10赋值运算a = a + 1 a+=1 布尔值:True 真 False 假 if True: pass while True: pass v = n ...

  6. Ubuntu16.04安装wps办公软件解决文字缺失

    先到wps官网下载linux版wps安装包 选择64位的alpha版本下载: 下载完后,同样是cd到Downloads目录,用dpkg命令来安装它: cd  Downloads/ sudo dpkg ...

  7. Keil sct分散加载文件

    官方说明:http://www.keil.com/support/man/docs/armlink/armlink_pge1401393372646.htm

  8. POJ 2208 Pyramids(求四面体体积)

    Description Recently in Farland, a country in Asia, a famous scientist Mr. Log Archeo has discovered ...

  9. POJ 2069 Super Star(计算几何の最小球包含+模拟退火)

    Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...

  10. 《javascript模式--by Stoyan Stefanov》书摘--字面量和构造函数

    二.字面量和构造函数 1,能够使用对象字面量时,就没理由使用new Object构造函数 // 一个空对象var 0 = new Object();console.log( o.constructor ...