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

检查一下啊!

Posted by chenxuan123456789 at 2012-07-30 11:42:07 on Problem 2236
#include <iostream>
#include <string>
using namespace std;
#define M 1010
typedef struct point
{
 int x;
 int y;
}point;
point p[M];
int father[M];
bool flag[M];
int n,d;
void make_set()
{
     for(int i=1;i<=M;i++)
     father[i]=i;
     memset(flag,false,sizeof(flag));
}
int find(int x)
{
    return father[x]==x?x:father[x]=find(father[x]);
}
void unionset(int a,int b)
{
     a=find(a);
     b=find(b); 
     if(a!=b&&(p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y)<=d*d)
     father[a]=b;
}
int main()
{
    int i,j;
    char str;
    scanf("%d%d",&n,&d);
    for(i=1;i<=n;i++)
    scanf("%d%d",&p[i].x,&p[i].y);
    int id;
	make_set();
    while(scanf("%c",&str)!=EOF)
    {
     if(str=='O')
     {
       scanf("%d",&id);
       flag[id]=true;
       for(i=1;i<=n;i++)
       if(flag[i]==true&&i!=id)
       unionset(i,id);
     }
     else
     if(str=='S')
     {
	 scanf("%d %d",&i,&j);
     if(find(i)==find(j))
     printf("SUCCESS\n");
     else
     printf("FAIL\n");
     }
	}
    return 1;
}
     

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