嘟嘟嘟




题意简述:给出一个光源\((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. sublime text3 JS语法检测插件

    首先ctrl+shift+P用包管理器安装sublimeLinter和sublimeLinter-jshint 前往node官网下载nodejs并安装 安装完node后打开命令行输入npm insta ...

  2. 使用TreeDMS进行MySQL数据库的Web页面远程管理

    在互联网应用蓬勃发展的时代背景下,各种各样的网络平台,网络应用,移动应用层出不穷,那么这些应用及平台都需要使用到数据库.如何高效的对数据进行日常维护.管理.监控成为迫切需要解决的问题. 基于web的方 ...

  3. Django实现验证码

    简单搞定生成验证码: 1.views.py from io import BytesIO import random from PIL import Image,ImageDraw,ImageFont ...

  4. Java web中的web-xml中标签定义之jsp-config

    <jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素. 其中<taglib>元素在JSP 1.2时就已 ...

  5. GIS 地理坐标分类

    wgs84 GPS系统直接通过卫星定位获得的坐标.(最基础的坐标.) gcj02 兲朝已安全原因为由,要求在中国使用的地图产品使用的都必须是加密后的坐标.这套加密后的坐标就是gcj02 google的 ...

  6. vmware虚拟机安装CentOS教程

    linux是企业最常用的服务器系统之一,CentOS是免费的,所以用的企业也挺多,今天给大家分享怎么在自己电脑的虚拟机中安装CentOS-6.5,以便用来玩耍,没事的时候可以学学linux的一些知识. ...

  7. 关于Spring MVC中的表单标签库的使用

    普通的MVC设计模式中M代表模型层,V代表视图层,C代表控制器,SpringMVC是一个典型的MVC设置模式的框架,对于视图和控制器的优化很多,其中就有与控制器相结合的JSP的表单标签库. 我们先简单 ...

  8. 安卓性能优化之清除Handler的Message和Runnable

    安卓性能优化之清除Handler的Message和Runnable Handler是由系统所提供的一种异步消息处理的常用方式,一般情况下不会发生内存泄露. 但既然是调优,当在A_Activity中使用 ...

  9. notepad 操作总结

    1.竖向选择 先把鼠标光标放在起始位置,然后同时按 Alt+Ctrl 或Alt+shift键,然后移动鼠标选取内容. Word中只能用Alt+Shift .

  10. Attribute+Reflection,提高代码重用

    这篇文章两个目的,一是开阔设计的思路,二是实例代码可以拿来就用. 设计的思路来源于<Effective c#>第一版Item 24: 优先使用声明式编程而不是命令式编程.特别的地方是,希望 ...