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表的题目,没有作任何参考,呵呵。纪念一下。

Posted by hello_hello at 2011-04-19 20:49:37 on Problem 1840
#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:
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