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 |
我也犯了楼下的错误,MD.我的代码没毒。#include<iostream> #include<vector> #include<algorithm> #include<cstring> #include<cmath> using namespace std; int N, d; struct point{ int x,y; }; inline bool valid(const point&a,const point&b) { int q=a.x-b.x;int w=a.y-b.y; if(q*q+w*w<=d*d)return true; else return false; } const int maxn=1010; point result[maxn]; int p[maxn]; bool revive[maxn]; vector<vector<int> >maze; int find(int x) { return p[x]==x?x:p[x]=find(p[x]); } void joint(int x,int y) { int p1=find(x),p2=find(y); p[p1]=p2; } int main() { cin>>N>>d; maze.resize(N); memset(revive,0,sizeof(revive)); for(int i=0;i<maxn;i++)p[i]=i; for(int i=0;i<N;i++)cin>>result[i].x>>result[i].y; for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) if(valid(result[i],result[j])) maze[i].push_back(j),maze[j].push_back(i); char ch; while(cin>>ch) { int i,j; if(ch=='O') { cin>>i; i--; revive[i]=true; for(j=0;j<maze[i].size();j++) { if(revive[maze[i][j]]) { joint(maze[i][j],i); } } } else if(ch=='S') { cin>>i>>j; if(find(i-1)!=find(j-1))cout<<"FAIL"<<endl; else cout<<"SUCCESS"<<endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator