当前位置:网站首页>【集训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;
}
边栏推荐
- The price of dividing gold bars
- Get together for ten years, tell your story, millions of gifts are waiting for you
- 『SignalR』. Net using signalr for real-time communication
- 【C语法】void*浅说
- ThreadLocal summary (to be continued)
- Playwright tutorial (II) suitable for Xiaobai
- Compile and decompile
- 力矩电机控制基本原理
- IFLYTEK smart office book air e-book reader makes my work life healthier
- If it is modified according to the name of the framework module
猜你喜欢

win10搭建flutter环境踩坑日记

TS:typora代码片段缩进显示异常(已解决)-2022.7.24

Compile and decompile

Ts:typera code fragment indentation display exception (resolved) -2022.7.24

The third day of Xiaobai programmer

MySQL --- 子查询 - 列子查询(多行子查询)

What have I experienced to become a harder tester than development?

Xiaobai programmer's first day

3dslicer importing medical image data

Xiaobai programmer's sixth day
随机推荐
ML-Numpy
Smart S7-200 PLC channel free mapping function block (do_map)
完啦,上班三个月,变秃了
Builder pattern
『Skywalking』. Net core fast access distributed link tracking platform
(1) Integrating two mapping frameworks of Dao
MapGIS格式转ArcGIS方法
Based on if nesting and function call
力矩电机控制基本原理
Playwright tutorial (I) suitable for Xiaobai
Fill the whole square with the float property
H5 lucky scratch lottery free official account + direct operation
According to the use and configuration of data permissions in the open source framework
平台架构搭建
JS interview questions
Win10 set up a flutter environment to step on the pit diary
mysql: error while loading shared libraries: libncurses.so. 5: cannot open shared object file: No suc
Why is the integer type 128 to byte -128
Nuclear power plants strive to maintain safety in the heat wave sweeping Europe
win10搭建flutter环境踩坑日记