Wireless Network POJ - 2236
标签:style sqrt end cin for less repair success const
#include
#includeusing namespace std;
const int N=1010;
int dx[N],dy[N];
int p[N];
int repair[N];
int n;
int d;
double get(int a,int b)
{
return sqrt(double(dx[a]-dx[b])*(dx[a]-dx[b])+(dy[a]-dy[b])*(dy[a]-dy[b]));
}
int find(int x)
{
if(p[x]!=x)
p[x]=find(p[x]);
return p[x];
}
int main()
{
cin>>n>>d;
for(int i=1;i)
p[i]=i;
for(int i=0;i)
cin>>dx[i]>>dy[i];
char cmd[2];
int len=0;
int p1;
int q;
while(cin>>cmd)
{
//如果是维修
if(cmd[0]==‘O‘)
{
cin>>p1;
p1--;
//存起来
repair[len++]=p1;
//每次维修,都和之前已经维修好的合并
for(int i=0;i1;i++)
if(repair[i]!=p1&&get(repair[i],p1)double(d))
p[find(repair[i])]=find(p1);
}
else if(cmd[0]==‘S‘)
{
cin>>p1>>q;
p1--,q--;
if(find(p1)==find(q))
cout"SUCCESS"endl;
else
cout"FAIL"endl;
}
}
return 0;
}
Wireless Network POJ - 2236
标签:style sqrt end cin for less repair success const
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12248481.html
评论