嘟嘟嘟
题意简述:给出一个光源\((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;
}