A Za, A Za, Fighting...

坚信:勤能补拙

PKU 3087 Shuffle'm Up

问题:
http://acm.pku.edu.cn/JudgeOnline/problem?id=3087

思路:
类似于模拟题的BFS,判重使用的是字符串哈希,哈希函数: ELFHash(见PKU 2503)

代码:
 1 int
 2 shuffle()
 3 {
 4     int i, count = 0;
 5     int hash_val;
 6     memset(hash, 0sizeof(hash));
 7     while(1) {
 8         for(i=0; i<2*len; i++) {
 9             if(i%2==0)
10                 queue[count][i] = tmp2[i/2];
11             else
12                 queue[count][i] = tmp1[i/2];
13         }
14         queue[count][i] = '\0';
15         strncpy(tmp1, queue[count], len);
16         strncpy(tmp2, queue[count]+len, len);
17         if(strcmp(queue[count], desire) == 0)
18             return count+1;
19         if(search(queue[count]) != -1)
20             return -1;
21         hash_val = ELFHash(queue[count]);
22         insert(hash_val, count);
23         ++count;
24     }
25 }

posted on 2010-07-28 13:09 simplyzhao 阅读(108) 评论(0)  编辑 收藏 引用 所属分类: B_搜索


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2010年10月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜