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表的题目,没有作任何参考,呵呵。纪念一下。#include<iostream> #include<cstring> #include<cstdio> using namespace std; const int MAX = 40000; struct node { int x; node *next; }nodes[MAX]; int a1,a2,a3,a4,a5; int abs(int x) { if(x>=0) return x; else return -x; } int main() { scanf("%d %d %d %d %d",&a1,&a2,&a3,&a4,&a5); memset(nodes,0,sizeof(nodes)); for(int i=-50;i<=50;i++) for(int j=-50;j<=50;j++) { if(i!=0 && j!=0) { int key=i*i*i*a1+j*j*j*a2; int tem=key; key=abs(key)%MAX; node *temp=&nodes[key]; node *point; point=new node; point->x=tem; point->next=NULL; while(temp->next!=NULL) temp=temp->next; temp->next=point; } } int ans=0; for(int i=-50;i<=50;i++) for(int j=-50;j<=50;j++) for(int k=-50;k<=50;k++) { if(i!=0 && j!=0 && k!=0) { int key=i*i*i*a3+j*j*j*a4+k*k*k*a5; int tem=key; key=abs(key)%MAX; node *point=&nodes[key]; while(point->next!=NULL) { point=point->next; if((point->x)+tem==0) ans++; } } } printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator