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. CC2640 LaunchPad入门试用-第一篇

    1. 先安装固件ble_cc26xx_setupwin32_2_01_00_44423.exe. 2. 打开IAR先找到一个例程测试一下D:\ti\simplelink\ble_cc26xx_2_01 ...

  2. 在Win10中通过命令行打开UWP应用

    近期由于需要在WinX菜单中添加几个UWP应用,但发现很难找到相应的命令行,Universal Apps 的快捷方式属性里也没有. 于是到网上搜了很久才找到一个E文的页面,试了一下确实可行,分享给大家 ...

  3. 使用git bash编译安装sysbench时遇到的坑

      Preface       When I was compiling the sysbench just now,I encountered some failures in the preced ...

  4. gitlab-登录账户遇到ERROR: Permission to XXX.git denied to user报错怎么办

    碰到这个问题就意味着没有访问账户的权限,没有把访问电脑与访问账户用ssh_key关联起来,解决流程: 1.查看本地是否有ssh_key 笔者用的是git bash来输入命令 ls -al ~/.ssh ...

  5. leetcode-汉明距离

    汉明距离 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意: 0 ≤ x, y < 231. 示例: 输入: x = ...

  6. 剑指offer-字符串的排列26

    题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描述: 输 ...

  7. windows store无法登陆的问题解决方案

    Windows应用商店或商店Apps无法打开或闪退的可选方法 (仅用于10565之前的Windows 10版本) 右键点击任务栏,选择"属性",切换到"导航"选 ...

  8. Code obfuscatio (翻译!)

    Description Kostya likes Codeforces contests very much. However, he is very disappointed that his so ...

  9. “Hello World!”团队第三周召开的第五次会议

    一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.代码地址 一.会议时间 2017年10月31日  11:45-12:17 二.会议地点: ...

  10. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset Trie

    题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 second ...