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

大牛帮忙看看,wrong answer 十几次了(数据对了)

Posted by hdjtdxacm at 2009-04-11 18:33:38 on Problem 2002
#include<stdio.h>
#include<algorithm>
#define INF 2000000000
using namespace std;
struct point
{
	int x,y;
    int d,X1,X2;
};
point a[1001];
point z[500001];
bool cmp(const point&a,const point&b)
{
	if(a.x != b.x)
		return a.x < b.x;
//	if(a.y != b.y)
    	return a.y < b.y;
 /*  	if(a.d != b.d)
    	return a.d < b.d;
   	if(a.X1!= b.X1)
    	return a.X1 < b.X1;
   	return a.X2 < b.X2;*/
}
int dis(point a,point b)
{
	return ((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
int main()
{
	int i,j,k,n,ans,count,t;
	while(scanf("%d",&n)&&n)
//while(scanf("%d",&n)!=EOF)
	{
		k = 0;
		 for(i = 1;i <= n;i++)
		 {
			 scanf("%d%d",&a[i].x,&a[i].y);
			 for(j = 1;j < i;j++)
			 {
		    	 z[++k].x = a[i].x + a[j].x;
				 z[k].y = a[i].y + a[j].y;
				 z[k].d = dis(a[i],a[j]);
				 if(a[i].x == a[j].x)
				 {
			    	 z[k].X1 = INF;
			    	 z[k].X2 = 0;
                  }
                  else
                  {
                      z[k].X1 = a[j].y - a[i].y;
                      z[k].X2 = a[j].x - a[i].x;
                  }
			 }
		 }
		 sort(z + 1,z + k + 1,cmp);
		 for(i = 1;i <= k;i++)
	    	 printf("%d %d %d %d %d\n",z[i].x,z[i].y,z[i].d,z[i].X1,z[i].X2);
		 i = 1;ans = 0;
		 while(i < k)
		 {
			 count = 1;
			 for(j = i + 1;j <=k ;j++)
			 {
			     if(z[i].x == z[j].x&&z[i].y == z[j].y&&z[i].d == z[j].d &&z[i].X1*z[j].X1 + z[i].X2*z[j].X2 == 0)
                           	 count++;
				 else
					 break;
			 }
			 ans += count*(count - 1)/2;
			 i = j;
		 }
		 printf("%d\n",ans);
	}
	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