嘟嘟嘟




题意简述:给出一个光源\((x_0, y_0)\),和一些圆,求投影区间。

这道题其实就是求经过\((x_0, y_0)\))的圆的切线。 刚开始我想到了一个用向量旋转的方法,但是写起来特别麻烦,于是在网上找到了一个特别巨的大佬的题解,主程序代码不过\(30\)行,这里分享给大家。 这是原文地址

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 505;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n;
struct Point
{
int x, y;
}P, C;
struct Node
{
db L, R;
bool operator < (const Node& oth)const
{
return L < oth.L;
}
}ans[maxn]; db dis(Point A, Point B)
{
return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
} int main()
{
while(scanf("%d", &n) && n)
{
P.x = read(); P.y = read();
for(int i = 1; i <= n; ++i)
{
C.x = read(); C.y = read(); db r = read();
db d = dis(P, C);
db a = asin(r / d), b = asin((P.x - C.x) / d);
ans[i].L = P.x - P.y * tan(a + b);
ans[i].R = P.x - P.y * tan(b - a);
}
sort(ans + 1, ans + n + 1);
db l = ans[1].L, r = ans[1].R;
for(int i = 2; i <= n; ++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);
enter;
}
return 0;
}

POJ1375 Intervals的更多相关文章

  1. POJ1375:Intervals——题解

    http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...

  2. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  3. [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  4. [LeetCode] Merge Intervals 合并区间

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  5. POJ1201 Intervals[差分约束系统]

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26028   Accepted: 9952 Descri ...

  6. Understanding Binomial Confidence Intervals 二项分布的置信区间

    Source: Sigma Zone, by Philip Mayfield The Binomial Distribution is commonly used in statistics in a ...

  7. Leetcode Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  8. LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。

    感觉有一点进步了,但是思路还是不够犀利. /** * Definition for an interval. * struct Interval { * int start; * int end; * ...

  9. Merge Intervals 运行比较快

    class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...

随机推荐

  1. 【C#】权限修饰符

    这个看了蛮多遍的,但是由于有一些一直不用,老是忘记,记录一下:) private  成员只能由同一个类(class)类型中的其他成员访问. family  成员可由派生类访问,不管那些类型是否在用一个 ...

  2. Hadoop源码学习笔记(6)——从ls命令一路解剖

    Hadoop源码学习笔记(6) ——从ls命令一路解剖 Hadoop几个模块的程序我们大致有了点了解,现在我们得细看一下这个程序是如何处理命令的. 我们就从原头开始,然后一步步追查. 我们先选中ls命 ...

  3. [javaSE] IO流(FIle对象递归文件列表)

    获取File对象,new出来,构造参数:String目录名 调用File对象的list()方法,获取String[]数组文件名称 循环数组,列出所有文件包含隐藏文件 递归列出所有的数据 定义一个静态方 ...

  4. Spark Pregel参数说明

    Pregel是个强大的基于图的迭代算法,也是Spark中的一个迭代应用aggregateMessage的典型案例,用它可以在图中方便的迭代计算,如最短路径.关键路径.n度关系等.然而对于之前对图计算接 ...

  5. JSONObject与null

    前言 今天在写代码的时候发现在 JSON 中 由于put了key对应的value为null,结果这个JSON键值对没有输出 org.json.JSONObject 在orgJSON 中,如果直接put ...

  6. JQuery实现获取多个input输入框的值,并存放在一个数组中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. js中获取css样式的两种方式

    1. 对象.style.样式名  弊端就是只能获取行内样式 2.window.getComputedStyle(对象,null); 最好用第二种方式 <!DOCTYPE html> < ...

  8. webstorm 打开后 一直停留在scanning files to index....,或跳出内存不够的提示框

    用着有时会这样,超级卡, 网上搜了下,原来如此,记录下,免得忘了. ------------------------- 说明: 在npm install 后,会出现Scanning files to ...

  9. C++学习笔记(8)----C++类的大小

    C++类的大小 (i) 如下代码: #include<iostream> using namespace std; class CBase { }; class CDerive :publ ...

  10. C#代码处理网页关于登录的code

    作者:血饮狂龙链接:https://www.zhihu.com/question/49452639/answer/117294801来源:知乎著作权归作者所有,转载请联系作者获得授权. private ...