poj 2236 Wireless Network(并查集)
2017-08-20 18:20
507 查看
一道水题.
看了acdreamer的博客才知道,我的代码慢,原来是用printf输出字符串,而不是puts
看了acdreamer的博客才知道,我的代码慢,原来是用printf输出字符串,而不是puts
/* xzppp */ #include <iostream> #include <vector> #include <cstdio> using namespace std; #define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #define lson MAXN,m,rt<<1 #define rson m+1,r,rt<<1|1 #define MP make_pair #define PB push_back typedef long long ll; typedef unsigned long long ULL; const int MAXN = 1000+17; const int MAXM = 20; const int INF = 0x7fffffff; const int MOD = 1e9+7; int par[MAXN],rk[MAXN]; int fd(int x) { if(par[x]==x) return x; else return par[x] = fd(par[x]); } void unite(int x,int y) { int a = fd(x); int b = fd(y); if(a==b) return; if(rk[a]>rk[b]) par[b] = a; else par[a] = b; if(rk[a]==rk[b]) rk[a]++; } struct point { double x,y; int id; }all[MAXN]; int main(int argc, char const *argv[]) { //FFF double n,m; cin>>n>>m; m*=m; for (int i = 0; i < n; ++i) { par[i] = i; rk[i] = 0; } for (int i = 0; i < n; ++i) { scanf("%lf%lf",&all[i].x,&all[i].y); all[i].id = i; } char cmd[10]; vector<point> v; while(scanf("%s",cmd)!=EOF) { if(cmd[0]=='O') { int id; scanf("%d",&id); id--; double a = all[id].x; double b = all[id].y; for (int i = 0; i < v.size(); ++i) { double x = v[i].x,y = v[i].y; double dis = (x-a)*(x-a) + (y-b)*(y-b); if(dis<=m) unite(v[i].id, id); } v.PB(all[id]); } else { int a,b; scanf("%d%d",&a,&b); a--;b--; if(fd(a)==fd(b)) puts("SUCCESS"); else puts("FAIL"); } } return 0; }
相关文章推荐
- POJ - 2236 Wireless Network (并查集)
- POJ 2236 Wireless Network(并查集)
- POJ 2236 并查集
- poj2236 并查集
- POJ 2236 Wireless Network(并查集)
- POJ 2236 Wireless Network 并查集
- POJ 2236 ——Wireless Network(并查集的应用)
- Wireless Network POJ - 2236 -并查集
- POJ 2236 Wireless Network 并查集
- POJ - 2236-Wireless Network(并查集)
- poj 2236 Wireless Network(并查集)
- POJ 2236 并查集
- 《挑战程序设计竞赛》2.4.2 数据结构-并查集 POJ1182 2236 1703 AOJ2170
- poj-2236 Wireless Network (并查集)
- POJ 2236 Wireless Network(并查集)
- POJ 2236(并查集)
- poj 2236:Wireless Network(并查集,提高题)
- POJ 2236 Wireless Network(并查集)
- POJ2236 并查集
- POJ 2236 Wireless Network(并查集)