1263 - Mines

All about problems in Volume 12. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
kushol
New poster
Posts: 4
Joined: Wed Jan 05, 2011 10:15 am

1263 - Mines

Post by kushol »

Why WA...........

Code: Select all

#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 2005

struct node{
	double x,y,d;
};
node sq[N];
int parent[N];
int find(int i){
	if ( i== parent[i])
		return i;
	else parent[i]=find(parent[i]);
}
int main()
{
	//freopen("in.txt","r+",stdin);
	int i,n,t,cas=1,pu,pv,ans,j;
	double m;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<=n;i++) parent[i]=i;
		for(i=0;i<n;i++){
			scanf("%lf %lf %lf",&sq[i].x,&sq[i].y,&sq[i].d);
		}
		for(i=0;i<n;i++){
			pu=find(i);
			m=(sq[i].d)/2.0;
			for(j=0;j<n;j++){
				if(i==j) continue;
				pv=find(j);
				if(pu!=pv){
					if(sq[j].x>=(sq[i].x-m)&&sq[j].x<=(sq[i].x+m)&&sq[j].y>=(sq[i].y-m)&&sq[j].y<=(sq[i].y+m)){
						parent[pv]=parent[pu];
					}
				}
			}
		}
		ans=0;
		for(i=0;i<n;i++){
			if(parent[i]==i)
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 1263- Mines

Post by brianfry713 »

Try solving this without using doubles.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 12 (1200-1299)”