POJ 2236并查集
2016-08-31 18:43
316 查看
#include"stdio.h" #include"iostream" #include"map" #include"set" using namespace std; const int maxn=1050; double d; int pre[maxn]; struct point{ double x,y; }a[maxn]; void init(int n) { for(int i=1;i<=n;i++) pre[i]=i; } int Find(int x) { return pre[x]==x?x:pre[x]=Find(pre[x]); } void join(int x,int y) { int xx=Find(x),yy=Find(y); if(xx!=yy) pre[xx]=yy; } double sqr(double x) { return x*x; } double dis(point x,point y) { return sqr(x.x-y.x)+sqr(x.y-y.y); } bool same(int x,int y) { return Find(x)==Find(y); } bool in(point a,point b) { return dis(a,b)<=d*d; } int main() { int n; scanf("%d%lf",&n,&d); map<int,int>Map; init(n); for(int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); char s[2]; while(scanf("%s",s)!=EOF) { if(s[0]=='O') { int y1; scanf("%d",&y1); for(int i=1;i<=n;i++) { if(Map[i]>0&&in(a[y1],a[i])) //电脑修好了,在范围之内 join(y1,i); } Map[y1]++; } else { int y1,y2; scanf("%d%d",&y1,&y2); //cout<<Map[y1]<<" "<<Map[y2]<<endl; if(Map[y1]>0&&Map[y2]>0&&same(y1,y2)) //两台电脑都是有用的 并且 在同一个连通分量中 puts("SUCCESS"); else puts("FAIL"); } } return 0; }
相关文章推荐
- poj 2236 Wireless Network(并查集)
- POJ 2236 Wireless Network(并查集)
- Wireless Network POJ - 2236------并查集
- pku 2236 poj 并查集一般题
- POJ 2236 Wireless Network (并查集)
- POJ-2236-Wireless Network(并查集)
- 并查集 POJ 2236
- POJ 2236 Wireless Network(并查集)
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
- poj 2236(并查集)
- POJ 2236 并查集
- POJ - 2236 Wireless Network(并查集)
- POJ 2236 Wireless Network(并查集)
- poj2236 Wireless Network 并查集
- POJ - 2236 Wireless Network ——并查集
- POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集
- poj 2236 并查集
- POJ2236 并查集 比1611 复杂一些
- poj 2236 并查集
- POJ 2236 Wireless Network(并查集)