| ||||||||||
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 |
为什么总是wa??!!!!!!!谁来救我#include <stdio.h> #include <iostream.h> #include <math.h> const N=1002; long a[N][2],c[N][N],num[N];//a x,y c[i][]:i can be reaech to c[i][?] long dist[N][N]; long n,d; long parent[N],height[N]; bool v[N];//which is had been repaired char ch; void inputing() { //scanf("%d%d",&n,&d); cin>>n>>d; int i,j; long distance; for (i=1;i<=n;i++) cin>>a[i][0]>>a[i][1]; //scanf("%d%d",&a[i][0],&a[i][1]); for (i=1;i<=n;i++) for (j=1;j<=n;j++) dist[i][j]=90000; for (i=1;i<=n;i++) for (j=1;j<=n;j++) { distance=(a[i][0]-a[j][0])*(a[i][0]-a[j][0]) + (a[i][1]-a[j][1])*(a[i][1]-a[j][1]); dist[i][j]= distance ; //dist[j][i]=dist[i][j]; } for (i=1;i<=n;i++) { num[i]=0; for (j=1;j<=n;j++) if (dist[i][j]<=d*d && i!=j) { num[i]++; c[i][num[i]]=j; } } } long find(long b) { int f,t; f=b; while (parent[f]!=0) f=parent[f]; while (b!=f) { t=parent[b]; parent[b]=f; b=t; } return f; } void unio(long u1,long u2) { u1=find(u1);u2=find(u2); if (u1!=u2) if (height[u1] <=height[u2]) { parent[u1]=u2; if (height[u1]==height[u2]) height[u2]++; } else parent[u2]=u1; } void work() { int i,u1,u2; if (ch=='O') { cin>>u1; for (i=1;i<=num[u1];i++) if ( v[c[u1][i]]==1 && i!=u1) unio(u1,c[u1][i]); v[u1]=1; } else { //scanf("%d%d",&u1,&u2); cin>>u1>>u2; u1=find(u1);u2=find(u2); if (u1==u2) cout<<"SUCCESS"<<endl; // printf("SUCCESS\n"); else cout<<"FAIL"<<endl;//printf("FAIL\n"); } } void main() { inputing(); while (cin>>ch) { work(); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator