摘要: 描述You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on a 阅读全文
posted @ 2009-11-22 21:58 laonan 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 问题:有一数组a,假设大小为max,我们想实现循环存储以充分利用空间。方法一: for(i=0;;i++){ a[i%max]=input(number);...} 这个即可实现当数组存满后跳到数组第一个存储。方法二:int k,i=0;while(1){ k=i&(max-1); (声名一下,此处max必须为2的幂次方) a[k]=input(number);... i++;}这个也可以实现上述效果。现在来比较一下两者的运行效率。前者中,运用了取模运算,可以先了解一下其运算过程:cpu提供加法运算器(有的提供乘法),其他运算都可以转换成加法,比如乘法可以累加,减法可以用反码转化,除法 阅读全文
posted @ 2009-11-22 10:25 laonan 阅读(280) 评论(0) 推荐(0) 编辑