博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2243解题报告
阅读量:4204 次
发布时间:2019-05-26

本文共 2393 字,大约阅读时间需要 7 分钟。

#include 
#include
using namespace std;bool checked[64];//int xstep[8] = {-1, -2, -2, -1, 1, 2, 2, 1};//int ystep[8] = {-2, -1, 1, 2, -2, -1, 1, 2};int knightmove(int sx, int sy, int ex, int ey, int len){ int move = 0; queue
> que; que.push(make_pair
(sx, sy)); int cur = 1, next = 0; while(!que.empty()) { pair
now = que.front(); que.pop(); cur--; if(now.first == ex && now.second == ey) { return move; } if(!checked[(now.first - 1) * len + (now.second - 2)] && now.first - 1 >= 0 && now.second - 2 >= 0) { que.push(make_pair
(now.first - 1, now.second - 2)); checked[(now.first - 1) * len + (now.second - 2)] = true; next++; } if(!checked[(now.first - 2) * len + (now.second - 1)] && now.first - 2 >= 0 && now.second - 1 >= 0) { que.push(make_pair
(now.first - 2, now.second - 1)); checked[(now.first - 2) * len + (now.second - 1)] = true; next++; } if(!checked[(now.first - 2) * len + (now.second + 1)] && now.first - 2 >= 0 && now.second + 1 < len) { que.push(make_pair
(now.first - 2, now.second + 1)); checked[(now.first - 2) * len + (now.second + 1)] = true; next++; } if(!checked[(now.first - 1) * len + (now.second + 2)] && now.first - 1 >= 0 && now.second + 2 < len) { que.push(make_pair
(now.first - 1, now.second + 2)); checked[(now.first - 1) * len + (now.second + 2)] = true; next++; } if(!checked[(now.first + 1) * len + (now.second - 2)] && now.first + 1 < len && now.second - 2 >= 0) { que.push(make_pair
(now.first + 1, now.second - 2)); checked[(now.first + 1) * len + (now.second - 2)] = true; next++; } if(!checked[(now.first + 2) * len + (now.second - 1)] && now.first + 2 < len && now.second - 1 >= 0) { que.push(make_pair
(now.first + 2, now.second - 1)); checked[(now.first + 2) * len + (now.second - 1)] = true; next++; } if(!checked[(now.first + 2) * len + (now.second + 1)] && now.first + 2 < len && now.second + 1 < len) { que.push(make_pair
(now.first + 2, now.second + 1)); checked[(now.first + 2) * len + (now.second + 1)] = true; next++; } if(!checked[(now.first + 1) * len + (now.second + 2)] && now.first + 1 < len && now.second + 2 < len) { que.push(make_pair
(now.first + 1, now.second + 2)); checked[(now.first + 1) * len + (now.second + 2)] = true; next++; } if(cur == 0) { move++; cur = next; next = 0; } } //cout<<"somewhere impossible."<
这道题和几乎一模一样。只是输入处理费了点功夫,C语言忘了好多。

转载地址:http://sxxli.baihongyu.com/

你可能感兴趣的文章
数据库的commit以及rollback
查看>>
动态加载JS脚本的4种方法
查看>>
《MySQL必知必会》——MySQL管理事务处理
查看>>
《MySQL必知必会》——笔记
查看>>
《Spring揭秘》——AOP(笔记)
查看>>
《TCP/IP详解卷3》——HTTP(笔记)
查看>>
JVM——main()方法的执行。
查看>>
观止——《从Decorator,Adapter模式看Java/IO库》
查看>>
《Erlang程序设计》——笔记
查看>>
Erlang开发环境Windows+Emacs+Distel配置
查看>>
Erlang的特点——小结
查看>>
Erlang的makefile——小例子
查看>>
蜗牛爬井——Erlang版本
查看>>
《Erlang程序设计》第8章习题解
查看>>
Erlang学习资料
查看>>
Erlang中的xml的转换
查看>>
一些Erlang的图形界面工具
查看>>
java-阻塞队列
查看>>
spring-cloud-eureka
查看>>
springcloud采坑-jason序列化中的Date对象
查看>>