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. 安装MySQLdb模块遭遇"fatal error: my_config.h: No such file or directory"的处理

    Issue       I encountered an error when I run the python script which need to import the module of & ...

  2. 「题目代码」P1049~P1053(Java)

    P1049 谭浩强C语言(第三版)习题6.5 import java.util.*; import java.io.*; import java.math.BigInteger; import jav ...

  3. Linux命令应用大词典-第35章 终端

    35.1 tty:显示当前连接到当前标准输入的终端设备文件名 35.2 consoletype:显示连接到标准输入的控制台类型 35.3 fgconsole:显示活动的虚拟终端数量 35.4 ming ...

  4. Maxscript-获取选中文件

    Maxscript - 获取选中文件 使用 .Net 的方法弹出窗口选择文件,并范围所有选中文件的路径“” Fn Fun_GetFilePaths strTitle strFilter = ( dia ...

  5. Unity操作小技巧

    1.操作类 1)F:选择物体后聚焦 2)V:选择物体的顶点,顶点吸附 3)Ctrl:摁住后拖动物体,可以按照系统设置的步长进行移动(Edit -> Snap setting) 4)Q W E R ...

  6. TW实习日记:第14天

    今天可以说是又忙又不忙了,忙是因为要赶bug,似乎总有种隐形的力量催着你交工,但实际上太多涉及后端接口的问题,所以又要等别人修改接口才能改bug,可以说真是十分蛋疼了. 改bug的最大心得就是:写好注 ...

  7. 【json提取器】- 提取数据的方法

    json 提取器的使用 方法 json 提取器  提取的结果   我用调试取样器进行查看

  8. VUE中关于表单提交的简单实现

    main.js import Vue from "../vue.js"; import App from "./App.js"; //启动 new Vue({ ...

  9. C语言文件基本操作

    1.用文本方式储存‘1’,‘0’,‘2’存入文件,然后用二进制方式从文件开头读出一个short型数据,并验证结果是否正确 #include<stdio.h> #include<str ...

  10. Java 集合框架之 Map

    Hashtable Hashtable 的实例有两个参数影响其性能:初始容量 和加载因子.容量 是哈希表中桶 的数量,初始容量就是哈希表创建时的容量.注意,哈希表的状态为 open:在发生“哈希冲突” ...