Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助 我HASH超时了...有没有高人指点一下...我用别的方法都过了...就HASH没过..#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator