当前位置:网站首页>【集训DAY13】Internet【并查集】
【集训DAY13】Internet【并查集】
2022-07-25 22:24:00 【VL——MOESR】

思路:
我们发现每次修理后只需要一个并查集就可以把相连的连上。
c o d e code code
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const int MAXN = 1010;
int n, d, fa[MAXN];
struct node {
int x, y;
}a[MAXN];
bool v[MAXN];
double dis(int x, int y) {
return sqrt((a[x].x - a[y].x) * (a[x].x - a[y].x) * 1.0 + (a[x].y - a[y].y) * (a[x].y - a[y].y) * 1.0);
}
int getfa(int x) {
if(x == fa[x]) return x;
return fa[x] = getfa(fa[x]);
}
int main() {
scanf("%d%d", &n, &d);
for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i].x, &a[i].y), fa[i] = i;
char ch;
int x, y;
scanf("%c", &ch);
while(scanf("%c", &ch) != EOF) {
if(ch == 'O') {
scanf("%d", &x);
v[x] = 1;
for(int i = 1; i <= n; i ++) {
if(v[i] && dis(x, i) <= d * 1.0) {
int xx = getfa(x), yy = getfa(i);
if(xx == yy) continue;
fa[xx] = yy;
}
}
}
else {
scanf("%d%d", &x, &y);
if(!v[x] || !v[y]) {
printf("FAIL\n");
scanf("%c", &ch);
continue;
}
int xx = getfa(x), yy = getfa(y);
if(xx == yy) printf("SUCCESS\n");
else printf("FAIL\n");
}
scanf("%c", &ch);
}
return 0;
}
边栏推荐
- xss-工具-Beef-Xss安装以及使用
- ThreadLocal 总结(未完待续)
- Why is the integer type 128 to byte -128
- mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No suc
- Based on if nesting and function call
- 『SignalR』. Net using signalr for real-time communication
- SQL basic statement DQL select and extract DML insert delete
- (1) Integrating two mapping frameworks of Dao
- torchvision
- Builder pattern
猜你喜欢

ThreadLocal 总结(未完待续)

The third day of Xiaobai programmer

If jimureport building block report is integrated according to the framework

Don't know mock test yet? An article to familiarize you with mock

Square root of X

It's over. I went to work for three months and became bald

Title: give a group of arrays, arranged from large to small and from small to large.

访问者模式(visitor)模式

沃达德软件:智慧城市方案

Matrix of C language
随机推荐
Call of addition, subtraction, multiplication and division of integer type only
淦,为什么 '𠮷𠮷𠮷' .length !== 3 ??
The third day of Xiaobai programmer
Flex layout
TFrecord写入与读取
JSP nine built-in objects
torchvision
Usage of in in SQL DQL query
沃达德软件:智慧城市方案
Smart S7-200 PLC channel free mapping function block (do_map)
The price of dividing gold bars
Why is the integer type 128 to byte -128
Redis foundation 2 (notes)
Leetcode 106. construct binary tree from middle order and post order traversal sequence
D3.js 学习
ThreadLocal 总结(未完待续)
torchvision
(1) Integrating two mapping frameworks of Dao
Xiaobai programmer's sixth day
科大讯飞智能办公本Air电纸书阅读器,让我的工作生活更加健康