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 1340502116 at 2016-07-17 22:09:58 on Problem 2236
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN=1005;
struct Node{
	int x,y;
}nodes[MAXN];
int n,d;
bool state[MAXN];
int par[MAXN];
void prep()
{
	for(int i=0;i<MAXN;i++)
	{
		par[i]=i;
	}
}
int fnd(int x)
{
	if(par[x]==x)
	{
		return x;
	}
	return par[x]=fnd(par[x]);
}
void unite(int x,int y)
{
	int a=fnd(x);
	int b=fnd(y);
	par[b]=a;
}
bool same(int x,int y)
{
	return fnd(x)==fnd(y);
}
double dist(int x1,int y1,int x2,int y2)
{
	return sqrt(1.0*(x1-x2)*(x1-x2)+1.0*(y1-y2)*(y1-y2));
}
int main()
{
	prep();
	memset(state,false,sizeof(state));
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&nodes[i].x,&nodes[i].y);
	}
	getchar();
	char op;
	while(scanf("%c",&op)!=EOF)
	{
		if(op=='O')
		{
			int id;
			scanf("%d",&id);
			state[id]=true;
			for(int i=1;i<=n;i++)
			{
				if(i==id)	continue;
				double len=dist(nodes[id].x,nodes[id].y,nodes[i].x,nodes[i].y);
				if(state[i]&&!same(i,id)&&len<=d)
				{
					unite(id,i);
				}
			}
		}
		else
		{
			int x,y;
			scanf("%d%d",&x,&y);
			if(state[x]&&state[y]&&same(x,y))
			{
				printf("SUCCESS\n");
			}
			else
			{
				printf("FAIL\n");
			}
		}
		getchar();
	}
	
	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