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 judas at 2006-11-17 22:29:18 on Problem 3025
In Reply To:终于过了....这道题WA的很诡异!!WA的兄弟近来看看 Posted by:humanjustic at 2006-11-17 21:41:51
> WA的原因:
> (1)没有考虑到两圆内含的情况!!
> 所以在判断 两圆心点距离dis 和 两圆半径关系时,有两种情况要同时考虑:
> dis< (r1+r2) && dis>(float)fabs(r1-r2) 这时才是真正的相交!!
> (2)没有考虑两圆重合情况!!
> 
> 但是我自己一开始WA的时候并不是由于没有考虑到上面情况WA的.
> 而是在用库函数memset()导致WA,这个情况很诡异..
> 下面有AC和WA的代码:
> 
> 这个是用了库函数memset()导致WA的:
> #include <iostream>
> #include <cmath>
> #define Max 1000000
> using namespace std;
> 
> struct Node
> {
> 	double x,y,r;
> }*data;
> 
> bool *visit;
> short Queuen[Max];
> int N,f,l;
> 
> void readdata()
> {
> 	int i;
> 
> 	data=new Node [N+1];
> 	
> 	for(i=1;i<=N;i++){
> 		cin>>data[i].x>>data[i].y>>data[i].r;
> 	}
> 	f=l=0;
> }
> 
> bool connect(short id1,short id2)
> {
> 	double dis;
> 	dis=(double)sqrt( (data[id1].x-data[id2].x)*(data[id1].x-data[id2].x)
> 		+(data[id1].y-data[id2].y)*(data[id1].y-data[id2].y) );
> 
> 	if(dis<(data[id1].r+data[id2].r)&&dis>(double)fabs(data[id1].r-data[id2].r)) return true;
> 	else if( (double)fabs(data[id1].x-data[id2].x)<=0.00000001
> 		&&(double)fabs(data[id1].y-data[id2].y)<=0.00000001
> 		&&(double)fabs(data[id1].r-data[id2].r)<=0.00000001)
> 		return true;
> 	return false;
> }
> 
> int BFS()
> {
> 	visit = new bool [N+1];
> 	//这里,本来想用memset()赋初值的,可是会错
>     memset(visit,0,sizeof(visit));
> 	int Count=1,i;
> 	short Id;
> 
> 	while(f<l&&l<Max){
> 		Id=Queuen[f++];
> 		visit[Id]=true;
> 
> 		for(i=1;i<=N;i++){
> 			if(!visit[i]){
> 				if(connect(Id,i)){
> 					visit[i]=true;
> 					Queuen[l++]=i;
> 					Count++;
> 				}
> 			}
> 		}
> 	}
> 	delete visit;
> 	return Count;
> }
> 
> int main()
> {
> 	while(cin>>N){
> 		if(N==-1) break;
> 
> 		readdata();
> 		int best=0,tmp;
> 		for(int i=1;i<=N;i++){
> 			f=l=0;
> 			Queuen[l++]=i;
> 			tmp=BFS();
> 			if(tmp>best) best=tmp;
> 		}
> 
> 		cout<<"The largest component contains "<<best<<" rings"<<endl;
> 	}
> 	return 0;
> }
> 
> 下面是AC的:
> #include <iostream>
> #include <cmath>
> #define Max 1000000
> using namespace std;
> 
> struct Node
> {
> 	double x,y,r;
> }*data;
> 
> bool *visit;
> short Queuen[Max];
> int N,f,l;
> 
> void readdata()
> {
> 	int i;
> 
> 	data=new Node [N+1];
> 	
> 	for(i=1;i<=N;i++){
> 		cin>>data[i].x>>data[i].y>>data[i].r;
> 	}
> 	f=l=0;
> }
> 
> bool connect(short id1,short id2)
> {
> 	double dis;
> 	dis=(double)sqrt( (data[id1].x-data[id2].x)*(data[id1].x-data[id2].x)
> 		+(data[id1].y-data[id2].y)*(data[id1].y-data[id2].y) );
> 
> 	if(dis<(data[id1].r+data[id2].r)&&dis>(double)fabs(data[id1].r-data[id2].r)) return true;
> 	else if( (double)fabs(data[id1].x-data[id2].x)<=0.00000001
> 		&&(double)fabs(data[id1].y-data[id2].y)<=0.00000001
> 		&&(double)fabs(data[id1].r-data[id2].r)<=0.00000001)
> 		return true;
> 	return false;
> }
> 
> int BFS()
> {
> 	visit = new bool [N+1];
> 	//memset(visit,0,sizeof(visit));//把这个去了
> 	int Count=1,i;
> 	short Id;
> 	//换for循环来赋初值..就没事!!!相当怪异!!!
> 	for(i=1;i<=N;i++)
> 		visit[i]=false;
> 
> 	while(f<l&&l<Max){
> 		Id=Queuen[f++];
> 		visit[Id]=true;
> 
> 		for(i=1;i<=N;i++){
> 			if(!visit[i]){
> 				if(connect(Id,i)){
> 					visit[i]=true;
> 					Queuen[l++]=i;
> 					Count++;
> 				}
> 			}
> 		}
> 	}
> 	delete visit;
> 	return Count;
> }
> 
> int main()
> {
> 	while(cin>>N){
> 		if(N==-1) break;
> 
> 		readdata();
> 		int best=0,tmp;
> 		for(int i=1;i<=N;i++){
> 			f=l=0;
> 			Queuen[l++]=i;
> 			tmp=BFS();
> 			if(tmp>best) best=tmp;
> 		}
> 
> 		cout<<"The largest component contains "<<best<<" rings"<<endl;
> 	}
> 	return 0;
> }
> Problem Id:3025  User Id:humanjustic 
> Memory:100K  Time:0MS
> Language:C++  Result:Accepted
> 
> 希望高手指点一下..memset()的具体用法..真是搞不懂!!
> 

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