Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一次A过 不废话贴代码

Posted by 351200 at 2011-08-17 17:22:18 on Problem 2236
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int MAXN=1010 ;
struct node
{
     int x  ;
     int y ;
} ;
node point[MAXN]  ;
int father[MAXN] ;
bool flag[MAXN] ;
int N,d ;
void makeset()
{
      for(int i=1 ;i<=N ;i++)
              father[i]=i ;
}
int  findset(int x)
{
      return  (father[x]==x) ?  x : father[x]=findset(father[x]) ;
}
void unionset(int a,int b)
{
        int distance=(point[a].x-point[b].x)*(point[a].x-point[b].x)+(point[a].y-point[b].y)*(point[a].y -point[b].y) ;
        a=findset(a) ;
        b=findset(b) ;
        if(distance<=d*d && a!=b)
        {
                 father[a]=b ;
        }
}
int main()
{
    int i ;
    cin>>N>>d ;
    for(i=1 ;i<=N ;i++)
          cin>>point[i].x>>point[i].y ;
     char ch ;
     int temp ;
     makeset() ;
     memset(flag,false ,sizeof(flag)) ;
     while(cin>>ch)
     {

               if(ch=='O')
               {
                   cin>>temp ;
                   flag[temp]=true ;
                   for(i=1 ;i<=N ;i++)
                         if(flag[i]==true && i!=temp)
                                 unionset(i,temp) ;
               }
               else
               {
                       int p,q ;
                       cin>>p>>q ;
                       if(findset(p)==findset(q))
                               cout<<"SUCCESS"<<endl  ;
                       else
                               cout<<"FAIL"<<endl ;
               }
     }
    return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator