| ||||||||||
| 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 | |||||||||
真变态 scanf(" %c",&ope)就超时, 改成cin>>ope 就过了。。#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn= 1005;
int father[maxn],flag[maxn];
int x[maxn],y[maxn];
int n,d;
void make()
{
for(int i=1; i<=n; i++)
{
father[i]= i;
flag[i]= 0;
}
}
int find(int v)
{
if(father[v]!=v)
father[v]= find(father[v]);
return father[v];
}
void merge(int a,int b)
{
int dis= (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
int xf= find(a);
int yf= find(b);
if(xf==yf) return ;
if(dis<=d*d)
father[xf]= yf;
}
int main()
{
char ope;
int q,p;
scanf("%d%d",&n,&d);
for(int i=1; i<=n; i++)
scanf("%d%d",&x[i],&y[i]);
make();
while(cin>>ope)
{
if(ope=='O')
{
scanf("%d",&p);
flag[p]= 1;
for(int i=1; i<=n; i++)
{
if(flag[i]==1)
merge(i,p);
}
}
else
{
scanf("%d%d",&p,&q);
if(find(p)==find(q))
{
printf("SUCCESS\n");
}
else
{
printf("FAIL\n");
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator