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 luishen at 2010-08-01 17:38:46 on Problem 1200 and last updated at 2010-08-01 17:43:26
一开始直接用ascii码对应。结果就怀具了。
应该是加和超过范围了。。
代码写得脑残了。。大家可能看着费劲。。让人看不懂的代码不是好代码。。用同样方法做过的童鞋应该容易看明白些。。仅供娱乐。。
#include <iostream>
using namespace std;
int  hash[20000000]={0};
char str[17000000];
int ascii_table[255]={0};//为字母赋值 
int map  [255]={0};//记录某个字母是否出现
int main ()
{

  int N;  scanf("%d",&N);
  int Nc; scanf("%d",&Nc);
     scanf("%s",&str);
  int j;
  int k;
  int temp;
  int ans=0;
  int ascii=0;
    for(j=0; str[j+N-1]!='\0'; j++)
     {  
       temp=0;
        for(k=0; k<N; k++)
		{   if (!map[(int)str[j+k]]) 
			{
			  map[(int)str[j+k]]=1;
              ascii_table[(int)str[j+k]]=ascii++;
			}
            temp=temp*Nc+ascii_table[(int)str[j+k]];
		}
      if (!hash[temp])
       {
           hash[temp]++;
           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