厦门首屈一指网站建设,网站开发培训光山,网页开发,如何知道网站开发语言目录
六宫数局
示例题目
简单模式
普通模式
困难模式 六宫数局
最强大脑同款项目。
找出一条给定起点和终点的路径#xff0c;每一步的方向任选#xff0c;在这个方向上移动的步数是当前数的质因数分解中2、3、5的次数。 示例题目 按照六边形坐标系来建立坐标系#…目录
六宫数局
示例题目
简单模式
普通模式
困难模式 六宫数局
最强大脑同款项目。
找出一条给定起点和终点的路径每一步的方向任选在这个方向上移动的步数是当前数的质因数分解中2、3、5的次数。 示例题目 按照六边形坐标系来建立坐标系用BFS算法求解
#include iostream
#includestring
#includestring.h
using namespace std;struct Node
{int x,y;
};int GetLen(Node a, Node b)
{if (a.x b.x)return GetLen(b, a);int dx b.x - a.x;int dy abs(b.y - a.y);if (dx % 2 0) {if (dy dx / 2)return dx;return dx dy - dx / 2;}int ym dx / 2 ((a.x (b.y a.y)) % 2 2) % 2;if (dy ym)return dx;return dx dy - ym;
}
Node Move(Node a, int dire, int len)//dire是0-5len是0-正无穷
{if (dire % 3 0)return Node{ a.x, a.y (dire 0 ? 1 : -1) * len };if (dire 1 || dire 5)return Node{ a.x (dire 1 ? 1 : -1)*len, a.y len / 2 (len % 2 ? (a.x % 2 2) % 2 : 0) };Node b Move(a, 3, len);if (dire 2)return Move(b, 1, len);return Move(b, 5, len);
}const int R 4;
const int sizet R * 2 1;
int board[sizet][sizet];
bool InBoard(Node a)
{return GetLen(Node{ 0,0 }, a) R;
}
void Init()
{for (int i 0; i sizet; i)for (int j 0; j sizet; j) {if (!InBoard(Node{ i - R,j - R })) {continue;}cin board[i][j];}
}
void bfs(Node a)
{queueNodeq;q.push(a);mapint, intm;m[a.x*R * 3 a.y] 1;int p[] { 5,2,3,5,3,2 };while (!q.empty()) {Node k q.front();q.pop();int n board[k.x R][k.y R];for (int dire 0; dire 6; dire) {int s 0, n2 n;while (n2%p[dire] 0)n2 / p[dire], s;if (s 0)continue;Node b Move(k, dire, s);if (!InBoard(b))continue;if (m[b.x*R * 3 b.y] 0)q.push(b);m[b.x*R * 3 b.y] 1;cout n - board[b.x R][b.y R] endl;}}
}int main()
{//freopen(D:/in.txt, r,stdin);Init();bfs(Node{ 0,-R });return 0;
}
输入
308 454 219 304 248 271 416 473 291 361 392 286 330 875 175 367 472 266 434 432 164 621 316 269 450 484 54 332 103 328 300 494 391 115 413 244 376 370 131 356 426 495 74 215 409 235 457 401 346 290 625 317 459 321 513 265 427 112 172 364 131
输出
54-244 54-434 244-625 244-432 434-332 434-286 625-513 432-459 332-409 332-330 286-432 286-271 513-300 459-103 330-875 330-164 330-432 330-286 330-271 330-416 300-391 300-401 300-131 300-103 300-621 300-367 875-472 164-131 164-473 416-401 621-409 621-308 472-74 308-875 74-413
求出来的最短路比示例路径短3步。
简单模式 普通模式 困难模式 文章转载自: http://www.morning.hrtfz.cn.gov.cn.hrtfz.cn http://www.morning.txrkq.cn.gov.cn.txrkq.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.zqwp.cn.gov.cn.zqwp.cn http://www.morning.jjzjn.cn.gov.cn.jjzjn.cn http://www.morning.bxch.cn.gov.cn.bxch.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn http://www.morning.crdtx.cn.gov.cn.crdtx.cn http://www.morning.ygztf.cn.gov.cn.ygztf.cn http://www.morning.tfrlj.cn.gov.cn.tfrlj.cn http://www.morning.fbmrz.cn.gov.cn.fbmrz.cn http://www.morning.flfdm.cn.gov.cn.flfdm.cn http://www.morning.llyqm.cn.gov.cn.llyqm.cn http://www.morning.cpwmj.cn.gov.cn.cpwmj.cn http://www.morning.dzpnl.cn.gov.cn.dzpnl.cn http://www.morning.jtsdk.cn.gov.cn.jtsdk.cn http://www.morning.pbksb.cn.gov.cn.pbksb.cn http://www.morning.dnbkz.cn.gov.cn.dnbkz.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.crkmm.cn.gov.cn.crkmm.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.qwdqq.cn.gov.cn.qwdqq.cn http://www.morning.pgmyn.cn.gov.cn.pgmyn.cn http://www.morning.xrsqb.cn.gov.cn.xrsqb.cn http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.lwzgn.cn.gov.cn.lwzgn.cn http://www.morning.mghgl.cn.gov.cn.mghgl.cn http://www.morning.ghkgl.cn.gov.cn.ghkgl.cn http://www.morning.bpmnc.cn.gov.cn.bpmnc.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.bqwsz.cn.gov.cn.bqwsz.cn http://www.morning.ranglue.com.gov.cn.ranglue.com http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.swzpx.cn.gov.cn.swzpx.cn http://www.morning.qttg.cn.gov.cn.qttg.cn http://www.morning.czgtt.cn.gov.cn.czgtt.cn http://www.morning.yrblz.cn.gov.cn.yrblz.cn http://www.morning.ydhck.cn.gov.cn.ydhck.cn http://www.morning.bmfqg.cn.gov.cn.bmfqg.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.xnpml.cn.gov.cn.xnpml.cn http://www.morning.krkwp.cn.gov.cn.krkwp.cn http://www.morning.mfsxd.cn.gov.cn.mfsxd.cn http://www.morning.ccjhr.cn.gov.cn.ccjhr.cn http://www.morning.bnjnp.cn.gov.cn.bnjnp.cn http://www.morning.rjrnx.cn.gov.cn.rjrnx.cn http://www.morning.knnhd.cn.gov.cn.knnhd.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn http://www.morning.bnkcl.cn.gov.cn.bnkcl.cn http://www.morning.trsdm.cn.gov.cn.trsdm.cn http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.hlwzd.cn.gov.cn.hlwzd.cn http://www.morning.tpdg.cn.gov.cn.tpdg.cn http://www.morning.bpptt.cn.gov.cn.bpptt.cn http://www.morning.ldwxj.cn.gov.cn.ldwxj.cn http://www.morning.jljiangyan.com.gov.cn.jljiangyan.com http://www.morning.mspkz.cn.gov.cn.mspkz.cn http://www.morning.zymgs.cn.gov.cn.zymgs.cn http://www.morning.c7512.cn.gov.cn.c7512.cn http://www.morning.cmzgt.cn.gov.cn.cmzgt.cn http://www.morning.zkgpg.cn.gov.cn.zkgpg.cn http://www.morning.nnttr.cn.gov.cn.nnttr.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.ndrzq.cn.gov.cn.ndrzq.cn http://www.morning.rkdzm.cn.gov.cn.rkdzm.cn http://www.morning.lwtfx.cn.gov.cn.lwtfx.cn http://www.morning.nmfwm.cn.gov.cn.nmfwm.cn http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.rttkl.cn.gov.cn.rttkl.cn http://www.morning.pmjhm.cn.gov.cn.pmjhm.cn http://www.morning.rqmr.cn.gov.cn.rqmr.cn http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn http://www.morning.knnc.cn.gov.cn.knnc.cn