当前位置:网站首页>Wireless network (preprocessing + concurrent search)
Wireless network (preprocessing + concurrent search)
2022-07-03 20:25:00 【MangataTS】
Topic link
https://www.acwing.com/problem/content/4269/
Ideas
because n For the range of 1k, Then we can put every point in advance d All points in the range are stored , This is an edge that is not clear whether it can be connected , Let's have another one v i s [ i ] vis[i] vis[i] Record the current number i Whether the computer is turned on . As for the relationship between these computers, we can maintain computers in the same set by merging and searching sets , We now have two operations :
- 'O’ operation : take p Computer on
- 'S’ operation : Inquire about p and q Whether in a collection
As mentioned earlier, we maintain this data relationship by merging and searching sets , For the first operation , We will p All around the computer Turn on the computer Merge (merge operation ) And put the current computer Mark as power on , For the second operation, we directly query p Computer and q Whether the computer is in the same set
Code
#include<bits/stdc++.h>
using namespace std;
//---------------- Custom part ----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){
return -x & x;}
const int N = 1e3+10;
//---------------- Custom part ----------------
ll t,n,d,m,fa[N];
struct Point{
ll x,y;
};
vector<Point> V;
vector<int> E[N];
bool vis[N];
ll find(ll x){
ll t = x;
while(t != fa[t]) t = fa[t];
while(x != fa[x]){
ll temp = fa[x];
fa[x] = t;
x = temp;
}
return x;
}
bool is_in(Point a,Point b){
ll x = (a.x - b.x),y = (a.y - b.y);
ll len = x * x + y * y;
return len <= d * d;
}
void init(){
ll x,y;
V.clear();
V.push_back({
0,0});
for(int i = 1;i <= n; ++i) {
vis[i] = false;
fa[i] = i;
cin>>x>>y;
V.push_back({
x,y});
E[i].clear();
}
for(int i = 1;i <= n; ++i) {
for(int j = 1;j <= n; ++j) {
if(i == j) continue;
if(is_in(V[i],V[j]))
E[i].push_back(j);
}
}
}
void slove(){
init();
char op;
while(cin>>op) {
ll u,v,k;
if(op == 'O'){
cin>>u;
k = find(u);
for(int i = 0,l = E[u].size();i < l; ++i) {
if(!vis[E[u][i]]) continue;
v = find(E[u][i]);
if(k != v) fa[v] = k;
}
vis[u] = true;
}
else{
cin>>u>>v;
u = find(u),v = find(v);
if(u == v)
cout<<"SUCCESS"<<endl;
else
cout<<"FAIL"<<endl;
}
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
while(cin>>n>>d){
slove();
}
return 0;
}
边栏推荐
- Battle drag method 1: moderately optimistic, build self-confidence (1)
- Example of peanut shell inner net penetration
- 2.3 other data types
- FPGA learning notes: vivado 2019.1 project creation
- Shortest path problem of graph theory (acwing template)
- Ruby replaces gem Alibaba image
- Basic command of IP address configuration ---ip V4
- String and+
- Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
- Global and Chinese market of electrolyte analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Nerfplusplus parameter format sorting
![How to read the source code [debug and observe the source code]](/img/0d/6495c5da40ed1282803b25746a3f29.jpg)
How to read the source code [debug and observe the source code]

Camera calibration (I): robot hand eye calibration

Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation

HCIA-USG Security Policy

Q&A:Transformer, Bert, ELMO, GPT, VIT

1.4 learn more about functions

IP address is such an important knowledge that it's useless to listen to a younger student?

Basic knowledge of dictionaries and collections

Node MySQL serialize cannot rollback transactions
随机推荐
Popularize the basics of IP routing
Global and Chinese market of speed limiter 2022-2028: Research Report on technology, participants, trends, market size and share
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028
Assign the CMD command execution result to a variable
Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!
An old programmer gave it to college students
Point cloud data denoising
Microservice knowledge sorting - search technology and automatic deployment technology
The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%
Teach you how to quickly recover data by deleting recycle bin files by mistake
Test changes in Devops mode -- learning and thinking
QT tutorial: signal and slot mechanism
It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET
Nerfplusplus parameter format sorting
2022 Xinjiang latest construction eight members (standard members) simulated examination questions and answers
Day6 merge two ordered arrays
AI enhanced safety monitoring project [with detailed code]
Golang type assertion and conversion (and strconv package)