| ||||||||||
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 |
MARK..第一个用标准并查集过的题目&&第一次套用模板#include<iostream> #include<fstream> #include<vector> #define MAXN 1003 #define _ufind_run(x) for(;p[t=x];x=p[x],p[t]=(p[x]?p[x]:x)) #define _run_both _ufind_run(i);_ufind_run(j) using namespace std; int p[MAXN],t;int n,d,l[1004][2]; void init(){memset(p,0,sizeof(p));} void set_friend(int i,int j){_run_both;p[i]=(i==j?0:j);} int is_friend(int i,int j){_run_both;return i==j&&i;} bool id(int i,int j) { if((l[i][0]-l[j][0])*(l[i][0]-l[j][0])+(l[i][1]-l[j][1])*(l[i][1]-l[j][1])>d*d) return 0; return 1; } int main() { //ifstream cin("0.txt"); vector<int>red; init(); int i,j,m,a,b; cin>>n>>d; for(i=1;i<=n;i++) cin>>l[i][0]>>l[i][1]; char c; while(cin>>c) { if(c=='O') { cin>>m; for(int i=0;i<red.size();i++) if(id(m,red[i])&&!is_friend(m,red[i])) set_friend(m,red[i]); red.push_back(m); } else if(c=='S') { cin>>a>>b; if(is_friend(a,b)) cout<<"SUCCESS"<<endl; else cout<<"FAIL"<<endl; } } // system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator