POJ1375 Intervals
嘟嘟嘟
题意简述:给出一个光源\((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的更多相关文章
- POJ1375:Intervals——题解
http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- [LeetCode] Data Stream as Disjoint Intervals 分离区间的数据流
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- [LeetCode] Merge Intervals 合并区间
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...
- POJ1201 Intervals[差分约束系统]
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26028 Accepted: 9952 Descri ...
- Understanding Binomial Confidence Intervals 二项分布的置信区间
Source: Sigma Zone, by Philip Mayfield The Binomial Distribution is commonly used in statistics in a ...
- Leetcode Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。
感觉有一点进步了,但是思路还是不够犀利. /** * Definition for an interval. * struct Interval { * int start; * int end; * ...
- Merge Intervals 运行比较快
class Solution { public: static bool cmp(Interval &a,Interval &b) { return a.start<b.star ...
随机推荐
- iptables-linux(ls)-inode-block
Part1:iptables 环境:centos6.7 目前我只配置了INPUT.OUTPUT和FORWORD都是ACCEPT的规则 由于想要先实现防火墙规则,所以前面的内容讲的是方法,后面是详解ip ...
- 添加FB登陆时,需要curl扩展
安装curl扩展遇到一个傻逼问题 [root@xxx openssl]# /usr/local/php/bin/phpizeCannot find config.m4.Make sure that y ...
- SublimeText3 插件的使用和本身的配置
--------------------20180109----------------------- Part1:如何设置代码字体变大变小 1.点击菜单栏 Sublime Text 中prefere ...
- redis 学习(一)
一.Redis概述 1.什么是NoSql NoSQL(NoSQL = Not Only SQL ),意即“不仅仅是SQL”,它泛指非关系型的数据库. 随着互联网2003年之后web2.0网站的兴起,传 ...
- shell文本操作
一.find查找命令的使用 1.find . -name "*.txt" 在当前目录下,查找以txt结尾的文件 2.find . -name "[a-z]" 在 ...
- CenOs7安装oracle图文详细过程(01)
原创作品,转载请在文章头部(显眼位置)注明出处:https://www.cnblogs.com/sunshine5683/p/10011441.html 1.检查必要的安装包是否安装 命令脚本: rp ...
- Hunger Snake 2
- java队列queue的我觉得很好的使用方式
LinkedList实现了queue接口,通常使用LinkedList 其中关键两个函数:offer().poll() offer()表示“排队”----插入到队列最前,poll()表示轮到了队列最前 ...
- 基于easyUI实现经典系统主界面
此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 相关文件介绍 1. home.jsp:系统主界面 <!DOCTYPE html PUBLIC "-//W3C ...
- HDU 2546(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2546 http://blog.csdn.net/xujinsmile/article/details/79694 ...