標籤:random .net find fir puts can code bitset ret
https://cn.vjudge.net/problem/POJ-2236
題意
有一個電腦網路的所有線路都壞了,網路中有n台電腦,現在你可以做兩種操作,修理(O)和檢測兩台電腦是否連通(S),只有修理好的電腦才能連通。連通有個規則,兩台電腦的距離不能超過給定的最大距離D(一開始會給你n台電腦的座標)。檢測的時候輸出兩台電腦是否能連通。
分析
注意審題。。只有修理好的才能算聯通。於是把所有修理好的並一起就行了。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <ctime>#include <vector>#include <queue>#include <map>#include <stack>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;#define ms(a, b) memset(a, b, sizeof(a))#define pb push_back#define mp make_pair#define pii pair<int, int>#define eps 0.0000000001#define IOS ios::sync_with_stdio(0);cin.tie(0);#define random(a, b) rand()*rand()%(b-a+1)+a#define pi acos(-1)const ll INF = 0x3f3f3f3f3f3f3f3fll;const int inf = 0x3f3f3f3f;const int maxn = 1000 + 100;const int maxm = 200000 + 10;const int mod = 998244353;int fa[maxn];int n,d;pair<int,int> p[maxn];bool check(pair<int,int> x,pair<int,int> y){ return (x.first-y.first)*(x.first-y.first)+(x.second-y.second)*(x.second-y.second)<=d*d;}int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]);}void Union(int x,int y){ int fx=find(x),fy=find(y); if(fx!=fy) fa[fx]=fy;}int tmp[maxn];int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("output.txt", "w", stdout);#endif scanf("%d%d",&n,&d); for(int i=1;i<=n;i++) scanf("%d%d",&p[i].first,&p[i].second),fa[i]=i; char op[3]; int x,y; int cnt=0; while(~scanf("%s",op)){ if(op[0]==‘O‘){ scanf("%d",&x); for(int i=0;i<cnt;i++){ if(tmp[i]!=x&&check(p[tmp[i]],p[x])){ Union(tmp[i],x); } } tmp[cnt++]=x; }else{ scanf("%d%d",&x,&y); int fx=find(x),fy=find(y); if(fx!=fy) puts("FAIL"); else puts("SUCCESS"); } } return 0;}
POJ - 2236 Wireless Network (並查集)