栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2318 Get Out!

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2318 Get Out!

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>#include<cmath>using namespace std;const int MAXN = 310;const double DINF = 1000000000.0;const double eps = 1e-6;struct Node { int v, next; double w;} nodes[MAXN*MAXN];int n;struct Circle { double x, y, r;} c[MAXN], p;int G[MAXN];bool vi[MAXN];int in[MAXN];double d[MAXN];int alloc;void add(int a, int b, double c) { nodes[alloc].v = b, nodes[alloc].next = G[a]; nodes[alloc].w = c; G[a] = alloc++;}bool spfa() { queue<int> Q; for(int i=1; i<=n; i++) { Q.push(i); vi[i] = 1; in[i] = 0; d[i] = 0; } while(!Q.empty()) { int u = Q.front(); Q.pop(); vi[u] = 0; for(int son = G[u]; son != -1; son = nodes[son].next) { int v = nodes[son].v; double w = nodes[son].w; if(d[v] > eps + d[u] + w) { d[v] = d[u] + w; if(!vi[v]) { in[v] ++; if(in[v] >= n) return false; vi[v] = 1; Q.push(v); } } } } return true;}double dist(int i, int j) { return sqrt((c[i].x - c[j].x)*(c[i].x - c[j].x) + (c[i].y - c[j].y)*(c[i].y - c[j].y));}int main(){ int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i=1; i<=n; i++) { scanf("%lf%lf%lf", &c[i].x, &c[i].y, &c[i].r); } scanf("%lf%lf%lf", &c[0].x, &c[0].y, &c[0].r); for(int i=1; i<=n; i++) { c[i].x -= c[0].x; c[i].y -= c[0].y; c[i].r += c[0].r; } c[0].x = c[0].y = 0; memset(G, -1, sizeof(G)); alloc = 0; for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { if(c[i].r + c[j].r - eps < dist(i, j)) continue; double C = acos((c[i].x*c[j].x+c[i].y*c[j].y) / (dist(i, 0) * dist(j, 0))); bool flag = (c[i].x*c[j].y - c[j].x*c[i].y) >= 0; add(i, j, flag?C:-C); add(j, i, !flag?C:-C); } } printf(spfa()?"YESn":"NOn"); if(T) printf("n"); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380099.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号