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

求助 我HASH超时了...有没有高人指点一下...我用别的方法都过了...就HASH没过..

Posted by sasnzy at 2006-07-12 21:53:34 on Problem 2859
#include<stdio.h>
#include<iostream>
using namespace std;
const int M=599981;
const int S=500000+1;
int HASH_TABLE[M];
int NEXT[S],X[S],Y[S];
int N,W,H;

void insert(int ind)
{
	int HASH_IND=(((__int64)X[ind]*1000000000+Y[ind])%M+M)%M;
	NEXT[ind]=HASH_TABLE[HASH_IND];
	HASH_TABLE[HASH_IND]=ind;
}
bool find(int x,int y)
{
	int HASH_IND=(((__int64)x*1000000000+y)%M+M)%M;
	int ind=HASH_TABLE[HASH_IND];
	while (ind)
	{
		if (X[ind]==x && Y[ind]==y) return true;
		ind=NEXT[ind];
	}
	return false;
}
int main()
{
	scanf("%d%d%d",&N,&W,&H);
	int i,j;
	for (i=1;i<=N;i++)
	{
		scanf("%d%d",&X[i],&Y[i]);
		insert(i);
	}
	int tot=0;
	for (i=1;i<=N;i++)
		if (find(X[i]+W,Y[i]) && find(X[i],Y[i]+H) && find(X[i]+W,Y[i]+H))
			tot++;
	printf("%d\n",tot);

}

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