POJ 2236 무선 네트워크 문제 해결 보고서 해체 세트

POJ 2236 무선 네트워크 문제 해결 보고서

문제 해결 아이디어 : 컴퓨터를 수리 한 경우 벡터는 각 시스템에 설정된 기준 컴퓨터의 거리 (d) 내의 저장 장치의 컴퓨터는 이러한 컴퓨터가 컴퓨터에 접속되어있다.
그림 삽입 설명 여기

#include<iostream>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<fstream>
#include<iomanip>
#include<vector>
#pragma warning(disable:4996)
#define INF 0x3f3f3f3f
#define ll long long
#define PI acos(-1.0)
const int N = 200010;
const int maxn = 1e5+10;
using namespace std;
int n, d;
int father[1005],visit[1005];
vector<int>v[1005];
struct node {
	int x, y;
}pos[1005];
int find(int t)
{
	while (t != father[t])
	{
		t = father[t];
	}
	return t;
}
void connect(int a, int b)
{
	int m = find(a);
	int n = find(b);
	father[m] = n;
}
void solve(int x, int y)
{
	int m = find(x);
	int n = find(y);
	if (m != n)
		cout << "FAIL" << endl;
	else
		cout << "SUCCESS" << endl;
}
int main()
{
	scanf("%d%d", &n, &d);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &pos[i].x, &pos[i].y);
		father[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i == j)
				continue;
			double sum = sqrt((pos[j].x - pos[i].x) * (pos[j].x - pos[i].x) + (pos[j].y - pos[i].y) * (pos[j].y - pos[i].y));
			if (sum <= d)
				v[i].push_back(j);
		}
	}
	char ch;
	int id,x, y;
	while (~scanf("%c", &ch))
	{
		if (ch == 'O')
		{
			scanf("%d", &id);
			visit[id] = 1;
			for (int i=0; i<v[id].size();i++)
			{
				int tem = v[id][i];
				if (1 == visit[tem])
					connect(id, tem);
			}
		}
		else if (ch == 'S')
		{
			scanf("%d%d", &x, &y);
			solve(x, y);
		}
	}
}



게시 64 개 원래 기사 · 원의 칭찬 0 · 조회수 1444

추천

출처blog.csdn.net/weixin_45566331/article/details/104905817