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

Re:又搞了2个小时,还是不知道哪里错了...谁能给小弟几组数据,谢谢了

Posted by lxp_rs at 2006-08-21 09:34:16 on Problem 2236
In Reply To:各位大牛,小弟初学并查集,按discuss里的提示写了一个,不知道为什么总是WA...请提示....(附代码) Posted by:lxp_rs at 2006-08-21 00:01:29
> //pku 2236
> #include "stdio.h"
> 
> int n,d;
> int f[1005];
> int flag[1005];
> 
> struct node
> {
>        int x;
>        int y;
> }com[1005];
> 
> int getfather(int p)
> {
>    int father;
>    if(f[p]==p) father=p;
>    else {
>        int k=getfather(f[p]);
>        f[p]=k;
>        father=f[p];
>    }
>    return father;
> }
> 
> void solve(int p)
> {
>     flag[p]=1;
>     int s=getfather(p);
>     for(int i=1;i<=n;i++)
>     {
>          if(flag[i]&&i!=p)
>          {
>              if((com[p].x-com[i].x)*(com[p].x-com[i].x)+(com[p].y-com[i].y)*(com[p].y-com[i].y)<=d*d)
>              {
>                  int t=getfather(i);
>                  if(s!=t)
>                  f[t]=s;
>              }
>          }            
>     }
>     
> }
> 
> void ans(int p,int q)
> {
>      if(getfather(p)==getfather(q)) printf("SUCCESS\n");
>      else printf("FALL\n");
> }
> 
> int main()
> {   
>     scanf("%d%d",&n,&d);
>     for(int i=1;i<=n;i++)
>     {
>         scanf("%d%d",&com[i].x,&com[i].y);  
>         f[i]=i;                      
>         flag[i]=0;
>     }    
>     char ch;
>     while(getchar(),scanf("%c",&ch)!=EOF)
>     {
>        if(ch=='O')
>        {
>            int p;
>            scanf("%d",&p);
>            solve(p);                      
>        }        
>        else if(ch=='S')
>        {
>            int p,q;
>            scanf("%d%d",&p,&q);
>            ans(p,q);
>        }    
>     }
>    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