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为什么会WA呢 谢谢了 帮忙看下#include <iostream> using namespace std; int a[4010],b[4010],c[4010],d[4010]; const int prim=10^7; class node { public: int key; int num; node *next; node() { key=0; num=0; next=NULL; } }hash[10^7]; void insert(int sum) { int aim; if(sum<0) { aim=(-sum)%prim; } else aim=sum%prim; node *p=&hash[aim]; if(p->num==0) { p->key=sum; p->next=NULL; p->num=1; return; } while(1) { if(p->key==sum) { p->num++; return ; } if(p->next==NULL) { p=p->next; break; } else p=p->next; } p=new node; p->next=NULL; p->num=1; p->key=sum; return; } int find(int sum) { int aim; if(sum<0) { aim=(-sum)%prim; } else aim=sum%prim; node *p=&hash[aim]; while(1) { if(p->key==sum) { return p->num; } if(p->next==NULL) { return 0; } else p=p->next; } return 0; } int main() { int sum,ans; ans=0; int n; cin>>n; int i,j; for(i=0;i<n;i++) { scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { sum=a[i]+b[j]; insert(sum); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { sum=c[i]+d[j]; sum=-sum; ans+=find(sum); } } //printf("%I64d\n",ans); cout<<ans<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator