标签:string main str poj2236 节点 continue lin eof als
//没什么好讲,被卡stringstream了,少用
//并查集
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
const int maxn = 1000 + 25;//节点数目
double dis(double x1,double y1,double x2,double y2)
{
return sqrt(double((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}//俩点之间距离
bool vis[maxn];//判断节点是否被连通
int father[maxn];
typedef struct
{
int x,y;
}node;
node arr[maxn];
int find(int node)
{
if(node!=father[node])
father[node] = find(father[node]);
return father[node];
}
int ans[maxn];//以它为顶点的个数
int main()
{
int n;
double d;
while(cin>>n>>d)
{
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;++i)
{
father[i] = i;//各自为单独节点
ans[i] = 1;
}
for(int i=1;i<=n;++i)
scanf("%d%d",&arr[i].x,&arr[i].y);
//string line;
char cmd[5];
while(scanf("%s",cmd)!=EOF)
{
int u,v;
if(cmd[0]==‘O‘)
{
scanf("%d",&u);
for(int i=1;i<=n;++i)
{
if(vis[i]&&i!=u)
{
double len = dis(arr[u].x,arr[u].y,arr[i].x,arr[i].y);
if(len > d)
continue;
int father1 = find(u);
int father2 = find(i);
if(father1!=father2/*&&ans1>=ans2*/)
{
father[father1] = father2;
}
}
}
vis[u] = true;
}else{
scanf("%d%d",&u,&v);
if(find(u)==find(v))
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
}
}
}
标签:string main str poj2236 节点 continue lin eof als
原文地址:https://www.cnblogs.com/newstartCY/p/11600558.html