题意:
分析:平面上有一堆圆,再给出一个圆P,问P能否在其他圆的缝隙中穿过到达无穷远处?
把每一个圆加上圆P的半径,圆P就成了一个点。
我们把每两个相交的圆之间连两条有向边,边权为P到线段的有向角度(互为相反数)。
然后spfa判断有没有负环即可。
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
const int MAXN = 309;
const double eps = 1e-10;
int n;
double sx, sy, sr;
struct cir
{
double x, y, r;
cir(double x = 0, double y = 0, double r = 0):x(x), y(y), r(r) {};
void read(){scanf("%lf%lf%lf", &x, &y, &r);};
}isl[MAXN], O;
struct Edge
{
int v, ne;
double d;
}edge[MAXN*MAXN];
int edgehead[MAXN], p = 1;
double dist[MAXN];
bool vis[MAXN];
int ct[MAXN];
cir operator - (const cir a, const cir b) {return cir(a.x-b.x, a.y-b.y, 0);}
double cross(const cir a, const cir b) {return a.x*b.y-a.y*b.x;}
double dot(const cir a, const cir b) {return a.x*b.x+a.y*b.y;}
double dis(const cir a, const cir b) {return sqrt(dot(a-b, a-b));}
int dcmp(double a)
{
if(fabs(a) <= eps) return 0;
else return a>0?1:-1;
}
bool check(int i, int j)
{
double dist = dis(isl[i], isl[j]);
if(dcmp(dist-isl[i].r-isl[j].r) < 0) return true;
else return false;
}
double calc(int i, int j)
{
double l1 = dis(isl[i], cir(sx, sy, 0)), l2 = dis(isl[j], cir(sx, sy, 0)), l3 = dis(isl[i], isl[j]);
return acos((l1*l1+l2*l2-l3*l3)/2/l1/l2);
}
void add(int u, int v, double d)
{
edge[p].v = v;edge[p].d = d;
edge[p].ne = edgehead[u];edgehead[u] = p++;
}
bool spfa()
{
queue<int> q;
for(int i = 1; i <= n; ++i) q.push(i), vis[i] = true;
while(!q.empty())
{
int u = q.front();q.pop();
vis[u] = false;
for(int i = edgehead[u]; i; i = edge[i].ne)
{
int v = edge[i].v;
double d = edge[i].d;
if(dcmp(dist[v]-dist[u]-d) > 0)
{
dist[v] = dist[u]+d;
if(vis[v]) continue;
else q.push(v), vis[v] = true;
if(++ct[v] > n)
return false;
}
}
}
return true;
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
isl[i].read();
scanf("%lf%lf%lf", &sx, &sy, &sr);
for(int i = 1; i <= n; ++i)
isl[i].r += sr;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
if(i != j && check(i, j))
{
int f = cross(isl[i]-cir(sx, sy, 0), isl[j]-cir(sx, sy, 0))>0?1:-1;
add(i, j, f*calc(i, j));
}
if(spfa()) puts("YES");
else puts("NO");
return 0;
}