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

真变态 scanf(" %c",&ope)就超时, 改成cin>>ope 就过了。。

Posted by aibing at 2013-04-14 13:13:33 on Problem 2236
#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:
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