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 rpggpr at 2005-12-29 19:37:42 on Problem 2002
#include <iostream>

using namespace std;

struct point
{
	int x;
	int y;
};

struct nnn
{
	int di;
	int a;
	int b;
};

int count;
point *p;

int inline dis(int i,int j)
{
	return (p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);
} 

bool inline cm(int a,int b)
{
	return a==b || a== (b<<1) ;
}

int inline compare(const void *a,const void *b)
{
	nnn *aa=(nnn *)a,*bb=(nnn *)b;
	int tmp=(aa->di-bb->di);
	if(tmp!=0) return tmp;
	tmp=aa->a-bb->a;
	if(tmp!=0) 
		return tmp;
	return aa->b-bb->b;
	
}


int main()
{
	int n;
	int ba=0;
	int re[100];
	while(cin>>n,n!=0)
	{
		p=new point[n];
		for(int i=0;i<n;i++)
		{
			cin>>p[i].x>>p[i].y;
		}
		count=0;
		int cc=n*(n-1);
		nnn *dd=new nnn[n*(n-1)];
		int *pp=new int[n];
		for (i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(i==j) continue;
				dd[count].a=i;
				dd[count].b=j;
				dd[count++].di=dis(i,j);
			}
		}
		qsort( (void *)dd , cc , sizeof(nnn),compare);
		count=0;
		for(i=0;i<cc;)
		{
			int tmp=0;
			int now=dd[i].di,nowa=-1;
			int j=i;
			for(int k=0;k<n;k++)
			{
				pp[k]=-1;
			}
			while(dd[j].di==now)
			{
				//cout<<dd[j].di<<"   "<<dd[j].a<<"  "<<dd[j].b<<endl;
				if(nowa!=dd[j].a)
				{
					nowa=dd[j].a;
					pp[nowa]=j;
					//cout<<nowa<<" "<<j<<"     ";
				}
				j++;
				tmp++;
			}
			//cout<<endl;
			if(tmp>3)
			{
				int begin,end1,end2,end3;
				for(int k1=i;k1<j;k1++)
				{
					begin=dd[k1].a;
					end1=dd[k1].b;
					if(pp[end1]==-1) continue;
					for(int k2=pp[end1];dd[k2].a==end1;k2++)
					{
						end2=dd[k2].b;
						if(end2==begin) continue;
						if(pp[end2]==-1) continue;
						for(int k3=pp[end2];dd[k3].a==end2;k3++)
						{
							end3=dd[k3].b;
							if(end3==end1) continue;
							if(pp[end2]==-1) continue;
							for(int k4=pp[end3];dd[k4].a==end3;k4++)
							{
								if(dd[k4].b==begin) 
								{
									count++;
									break;
								}
							}
						}
					}
				}
			}
			i=j;
			
		}
		delete[] pp;
		delete[] dd;
		delete[] p;
		count/=8;
		re[ba++]=count;
		//cout<<count<<endl;
	}
	for(int h=0;h<ba;h++)
		cout<<re[h]<<endl;
	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