当前位置: 首页>>代码示例>>C++>>正文


C++ CState::toAbs方法代码示例

本文整理汇总了C++中CState::toAbs方法的典型用法代码示例。如果您正苦于以下问题:C++ CState::toAbs方法的具体用法?C++ CState::toAbs怎么用?C++ CState::toAbs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CState的用法示例。


在下文中一共展示了CState::toAbs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
  initSolution();

  dist.resize(64 * 64, numeric_limits<int>::max());
  path.resize(64 * 64);

  CState start = readState();
  CState end = readState();

  bfs(start);

  vector<uint> ans;

  for (uint v = end.toAbs(); v != startIndex; v = path[v])
    ans.push_back (v);

  for (uint i = ans.size() - 1; i > 0; i--)
    {
      pair<int, CPoint> const diff = CState(ans[i - 1]).diff(CState(ans[i]));
      printf("%d %c%d\n", diff.first, coord2C(diff.second.x), diff.second.y);
    }

  postActions();
  return 0;
}
开发者ID:Esenin,项目名称:GraphAlgorithms,代码行数:26,代码来源:r.cpp

示例2: bfs

void bfs(CState const &s)
{
  vector<CPoint> possible;
  possible.push_back(CPoint(1 ,2));
  possible.push_back(CPoint(2, 1));
  possible.push_back(CPoint(2, -1));
  possible.push_back(CPoint(1, -2));
  possible.push_back(CPoint(-1, -2));
  possible.push_back(CPoint(-2, -1));
  possible.push_back(CPoint(-2, 1));
  possible.push_back(CPoint(-1, 2));

  queue<CState> q;
  q.push (s);
  path[s] = startIndex;
  dist[s] = 0;

  while (!q.empty())
    {
      CState const curr = q.front();
      q.pop();

      for (CPoint const &mov : possible)
        {
          // for the first horse
          CState nextSt1(curr.p1 + mov, curr.p2);
          if (nextSt1 && dist[curr] + 1 < dist[nextSt1])
            {
              q.push(nextSt1);
              dist[nextSt1] = dist[curr] + 1;
              path[nextSt1] = curr.toAbs();
            }

          // for the second one
          CState nextSt2(curr.p1, curr.p2 + mov);
          if (nextSt2 && dist[curr] + 1 < dist[nextSt2])
            {
              q.push(nextSt2);
              dist[nextSt2] = dist[curr] + 1;
              path[nextSt2] = curr.toAbs();
            }
        }
    }
}
开发者ID:Esenin,项目名称:GraphAlgorithms,代码行数:44,代码来源:r.cpp

示例3: diff

  pair<int, CPoint> diff(CState const &next) const
  {
    if (toAbs() == next.toAbs())
      return make_pair<int, CPoint>(-1, CPoint(1, 1));

    if (p1 == next.p1)
      return make_pair<int, CPoint>(2, CPoint(p2));
    else
      return make_pair<int, CPoint>(1, CPoint(p1));
  }
开发者ID:Esenin,项目名称:GraphAlgorithms,代码行数:10,代码来源:r.cpp


注:本文中的CState::toAbs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。