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 bingshen at 2011-02-08 17:11:19 on Problem 2002
Source Code

Problem: 2002  User: bingshen 
Memory: N/A  Time: N/A 
Language: C++  Result: Wrong Answer 

Source Code 
#include<stdio.h>
#include<vector>
#include<algorithm>
#define maxn 1000

using namespace std;

struct point
{
	int x;
	int y;
};
point p[maxn+5];
vector<point>hash[maxn+5][maxn+5];

bool cmp(point a,point b)
{
	if((a.y<b.y)||(a.y==b.y&&a.x<b.x))
		return true;
	return false;
}

bool judge(int a,int b)
{
	int i,x1,y1,x2,y2,x,y,px,py;
	bool k1=false,k2=false;
	x=p[a].y-p[b].y;
	y=p[b].x-p[a].x;
	px=x+p[a].x;
	py=y+p[a].y;
	x1=(x+p[a].x)%maxn;
	y1=(y+p[a].y)%maxn;
	if(x1<=0)
		x1=x1+maxn;
	if(y1<=0)
		y1=y1+maxn;
	for(i=0;i<hash[x1][y1].size();i++)
	{
		if(hash[x1][y1][i].x==px&&hash[x1][y1][i].y==py)
		{
			k1=true;
			break;
		}
	}
	px=x+p[b].x;
	py=y+p[b].y;
	x2=(x+p[b].x)%maxn;
	y2=(y+p[b].y)%maxn;
	if(x2<=0)
		x2=x2+maxn;
	if(y2<=0)
		y2=y2+maxn;
	for(i=0;i<hash[x2][y2].size();i++)
	{
		if(hash[x2][y2][i].x==px&&hash[x2][y2][i].y==py)
		{
			k2=true;
			break;
		}
	}
	if(k1&&k2)
		return true;
	return false;
}

void init()
{
	int i,j;
	for(i=0;i<=maxn;i++)
		for(j=0;j<=maxn;j++)
			hash[i][j].clear();
}

int main()
{
	int i,j,n,x,y;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)
			break;
		init();
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&p[i].x,&p[i].y);
			x=p[i].x%maxn;
			y=p[i].y%maxn;
			if(x<=0)
				x=x+maxn;
			if(y<=0)
				y=y+maxn;
			hash[x][y].push_back(p[i]);
		}
		if(n<=3)
		{
			printf("3\n");
			continue;
		}
		sort(p+1,p+1+n,cmp);
		int ans=0;
		for(i=1;i<=n;i++)
			for(j=i+1;j<=n;j++)
			{
				if(judge(i,j))
					ans++;
			}
		printf("%d\n",ans/2);
	}
	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