本文整理汇总了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;
}
示例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();
}
}
}
}
示例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));
}