Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: