Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题有点水,然而开始时还是把平方根漏掉了。。。#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #include <string> #include <queue> #include <vector> using namespace std; const int maxn=1005; typedef struct Node{ int x,y; }node; node num[maxn]; int fa[maxn]; int find(int a){ if(a==fa[a]) return a; else return fa[a]=find(fa[a]); } void merge(int a,int b){ int ffa=find(a),ffb=find(b); if(ffa==ffb) return ; else{ fa[ffa]=ffb; } } double dis(node a,node b){ return (double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } int main() { int n; double d; memset(num,0,sizeof(num)); scanf("%d %lf",&n,&d); d*=d; for(int i=1;i<=n;i++) scanf("%d %d",&num[i].x,&num[i].y); char c; int a,b; while(cin>>c){ if(c=='O'){ scanf("%d",&a); fa[a]=a; for(int i=1;i<=n;i++){ if(i==a) continue; if(fa[i]!=0&&dis(num[i],num[a])<=d){ merge(i,a); } } } else{ scanf("%d %d",&a,&b); if(find(a)==find(b)) printf("SUCCESS\n"); else printf("FAIL\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator