嘟嘟嘟




题意简述:给出一个光源\((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. 使用SQL语句创建数据库1

    创建一个数据文件和一个日志文件的数据库 user master --只想当前使用的数据库 GO --批处理标志 create database BOOK --创建book数据库 on primary ...

  2. Java学习--Jsp简介

  3. memcached 细究(一)

    memcached是高性能的分布式的内存缓存服务器.由国外社区网站LIVEJOURNAL的开发团队开发. 使用目的: 通过缓存数据库查询结果,减少数据库的访问次数,以提高动态web应用的速度.提高可扩 ...

  4. java常见异常(转载)

    版权声明: https://blog.csdn.net/qq_32595075/article/details/80059834 一般面试中java Exception(runtimeExceptio ...

  5. ETL第一篇(Kettle Spoon) 初遇

    ETL第一篇(Kettle Spoon) 初遇 ETL第二篇 调用webservice 简介 Kettle 是一款国外开源的 ETL 工具,纯 Java 编写,绿色无需安装,数据抽取高效稳定(数据迁移 ...

  6. 使用Tensorflow和MNIST识别自己手写的数字

    #!/usr/bin/env python3 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data ...

  7. zoj 1048

    这道题提醒了我一个问题,怎么在while(cin>>a[i])下中断 #include<iostream> #include<cmath> #include< ...

  8. MVC 中使用kindEditor 图片上传在IE 上进行上传出现的问题

    在IE 上使用KindEditor 进行单张图片上传的时候会出现一个下载安全警告,这样将会造成图片上传失败,出现的错误页面:

  9. BZOJ1258 [CQOI2007]三角形

    Description 画一个等边三角形,把三边的中点连接起来,得到四个三角形,把它们称为T1,T2,T3,T4,如图1.把前三个三角形也这样划分,得到12个更小的三角形:T11,T12,T13,T1 ...

  10. SQL-字符串运算符和函数

    COALESCE(columnname,string) 函数 将 NULL 值作为字符串(用空字符串或其他字符串替换 NULL)- 接受一列输入值(字段)如果该字段为 NULL,则返回后面替换的字符串 ...