日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 2236 Wireless Network (并查集)

發(fā)布時(shí)間:2025/7/14 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 2236 Wireless Network (并查集) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Wireless Network

題目鏈接:

http://acm.hust.edu.cn/vjudge/contest/123393#problem/A

Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats:

  • "O p" (1 <= p <= N), which means repairing computer p.
  • "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.
  • The input will not exceed 300000 lines.

    Output

    For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

    Sample Input

    4 1
    0 1
    0 2
    0 3
    0 4
    O 1
    O 2
    O 4
    S 1 4
    O 3
    S 1 4

    Sample Output

    FAIL
    SUCCESS

    題意:

    給出n個(gè)點(diǎn)的坐標(biāo),一開始任意兩點(diǎn)均不聯(lián)通;
    接著給出多個(gè)操作:

  • 恢復(fù)點(diǎn)x的聯(lián)通性,即x可與其他已恢復(fù)的點(diǎn)連接.
  • 查詢點(diǎn)x和y是否可達(dá).
    (定義可達(dá):距離小于d,或者經(jīng)過多條小于d的邊)
  • 題解:

    很明顯的并查集模版題.
    距離小于等于d即可合并;
    查詢時(shí)輸出兩點(diǎn)是否在同一集合.
    (不要把FAIL輸出成FALL).

    注意:先將與點(diǎn)i距離不超過d的點(diǎn)存起來;
    當(dāng)恢復(fù)點(diǎn)i后,枚舉可連接的點(diǎn),只有兩點(diǎn)都被恢復(fù)時(shí)才能合并.

    代碼:

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #define LL long long #define eps 1e-8 #define maxn 1200 #define inf 0x3f3f3f3f #define IN freopen("in.txt","r",stdin); using namespace std;int fa[maxn]; int rank[maxn];void init_set() {for(int i=0; i<maxn; i++) {fa[i] = i;rank[i] = 0;} }int find_set(int x) {return fa[x] = (x==fa[x]? x:find_set(fa[x])); }void unit_set(int x, int y) {x = find_set(x);y = find_set(y);if(rank[x] < rank[y]) swap(x, y);fa[y] = x;if(rank[x] == rank[y]) rank[x]++; }LL D; bool dis[maxn][maxn]; LL x[maxn],y[maxn]; bool vis[maxn];int main(int argc, char const *argv[]) {//IN;int n;while(scanf("%d %lld", &n,&D) != EOF){D = D*D;init_set();memset(dis, 0, sizeof(dis));memset(vis, 0, sizeof(vis));for(int i=1; i<=n; i++) scanf("%lld %lld", &x[i],&y[i]);for(int i=1; i<=n; i++) {for(int j=1; j<=n; j++) {if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) <= D) {dis[i][j] = dis[j][i] = 1;}}}char c; int x,y;while(scanf("%c",&c) != EOF) {if(c=='O') {scanf("%d", &x);vis[x] = 1;for(int i=1; i<=n; i++) if(dis[x][i] && vis[i])unit_set(i, x);}else if(c=='S') {scanf("%d %d", &x,&y);if(find_set(x) == find_set(y)) puts("SUCCESS");else puts("FAIL");}}}return 0; }

    轉(zhuǎn)載于:https://www.cnblogs.com/Sunshine-tcf/p/5699043.html

    總結(jié)

    以上是生活随笔為你收集整理的POJ 2236 Wireless Network (并查集)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 九九热九九热 | 中文字幕播放 | 欧美αv| 欧美丰满老熟妇aaaa片 | 在线免费观看国产视频 | 麻豆精品国产传媒 | 国产精品人人做人人爽人人添 | av网址在线免费观看 | 国产国语对白 | 国产嫩草影院久久久 | 久久人妻一区二区 | 91丝袜呻吟高潮美腿白嫩 | 超碰2 | 日本韩国中文字幕 | 国产精品久久久久久免费 | 国产精品96| 深夜视频在线观看免费 | 日韩中文字幕国产 | 亚洲一级中文字幕 | 97久草| 91玉足脚交嫩脚丫在线播放 | 国产91视频在线 | 成人av地址| 天堂一区 | 精品亚洲永久免费精品 | 免费爱爱网址 | 综合网久久 | 婷婷九月| 法国空姐 在线 | 又黄又高潮的视频 | 新版红楼梦在线高清免费观看 | 欧美整片在线 | 国产精成人品免费观看 | 国产不卡高清 | xxxxxx日本 | 日日干夜夜拍 | 综合亚洲色图 | 一区二区三区久久久久 | 看日本黄色录像 | 国产高潮视频在线观看 | 尤物国产视频 | 人成在线免费视频 | 蜜桃av噜噜一区二区三区 | 高跟鞋和丝袜猛烈xxxxxx | 91福利一区 | 中文字幕无码乱码人妻日韩精品 | 毛片免费播放 | 丰满少妇被猛烈进入一区二区 | 国产毛片一区二区 | 极品人妻一区二区三区 | 暖暖免费观看日本版 | 国产1级片 | 国产午夜啪啪 | 欧美午夜精品一区二区 | 人妻精品久久久久中文 | 裸尼姑熟蜜桃 | 欧美熟妇精品久久久久久 | 中国少妇av | 久久夜色精品亚洲 | 亚洲AV无码精品色 | 欧美一卡二卡三卡 | 亚洲a v网站 | 超碰公开免费 | 亚洲第一女人av | 99久久精品免费看国产四区 | 曰批女人视频在线观看 | 波多野吉衣在线视频 | 99视频免费| 国产综合图区 | 色xxxx| 久久国产色| 色婷婷成人| 五月色婷 | 天天操天天拍 | 色欧美色 | 日韩亚洲一区二区 | 涩涩网站免费 | 亚洲丁香网 | 亚洲s码欧洲m码国产av | 欧美亚洲影院 | www.亚洲免费 | 免费看黄色漫画 | 欧美激情国产精品免费 | 国产特黄aaaaa毛片 | 亚洲乱熟女一区二区 | 国产美女视频网站 | 在线免费中文字幕 | 久久av色 | 99激情视频 | 无码人妻精品一区二区三区9厂 | 欧美一区,二区 | 国产精品美女在线观看 | 成人av观看| 大黑人交交护士xxxxhd | 黄色三级在线视频 | 永久视频在线观看 | 丁香亚洲| 日本黄色大片免费 | 日本人的性生活视频 |