+ -
当前位置:首页 → 问答吧 → 请教镜像算法

请教镜像算法

时间:2011-08-18

来源:互联网

一个n*m的网格,我想取到在x轴方向的镜像的算法,比如说,5*5的格子,当我取到索引值为0的点的时候,应该直接可以取到索引值为4的顶点,同样,取到索引值为1的顶点时候可以取到索引值为3的顶点,相反地,如果遍历到索引值为4的顶点,实际上我取到的是索引值为0的顶点

作者: cl781121   发布时间: 2011-08-18

// m行n列
int ReflectX(int index, int n/*, int m*/) // m这里没用
{
  assert(n);
  int row = index / n;
  int col = index % n;
  col = n - 1 - col;
  return row * n + col;
}

作者: popy007   发布时间: 2011-08-19