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函数,同时弱问下,这题咋判重啊- -|||也不是啥新鲜的,RK法,PRIME取999983,刚好没有重复。。。(这函数的确比较NB。。。) void getHash ( char a[] , int key ) { long long int sum = 0; int len = strlen ( a ); for ( int i = 0;i < len;i++ ) { sum = ( sum * 26 + a[i] ); } int k = sum % prime; if ( hash[k] == 0 ) { hash[k] = key; return ; } } 写法就是这样 关键我有点想不通,如果想判重的时候,实在没想好怎么写,hash[k]=key,这里的key必然得取装了英文的数组的下标啊,那查询的时候查到一个hash[position]不等于0的话,它也没法判断是不是往下找。。。迷惑- -||| 麻烦用HASH做的童鞋发个代码到站内哈,谢谢:) Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator