1151. 魔板
来源:互联网 发布:电脑硬盘测评软件 编辑:程序博客网 时间:2024/05/19 19:40
用set判重会被打么……
#include <iostream>#include <queue>#include <set>using namespace std;int goal;int maxStep;queue<int> searchingList;queue<string> stepList;set<int> been;void init() { goal = 0; for(int i = 0; i < 8; i++) { int bit; cin >> bit; goal = 10 * goal + bit; } while(!searchingList.empty()) { searchingList.pop(); } while(!stepList.empty()) { stepList.pop(); } searchingList.push(12348765); stepList.push(""); been.clear();}int a(int board) { return board % 10000 * 10000 + board / 10000;}int b(int board) { return (board / 10000 % 10 * 1000 + board / 10000 / 10) * 10000 + (board % 10000 % 10 * 1000 + board % 10000 / 10);}int c(int board) { return board / 10000000 * 10000000 + board / 100 % 10 * 1000000 + board / 1000000 % 10 * 100000 + board % 100000 / 1000 * 1000 + board / 10 % 10 * 100 + board / 100000 % 10 * 10 + board % 10;}void search() { while(!searchingList.empty() && !stepList.empty()) { int bo = searchingList.front(); string st = stepList.front(); if(st.length() > maxStep) { cout << -1 << endl; return; } else if(bo == goal) { cout << st.length() << ' ' << st << endl; return; } else if(been.find(bo) != been.end()) { searchingList.pop(); stepList.pop(); continue; } been.insert(bo); searchingList.pop(); stepList.pop(); searchingList.push(a(bo)), stepList.push(st+"A"); searchingList.push(b(bo)), stepList.push(st+"B"); searchingList.push(c(bo)), stepList.push(st+"C"); }}int main() { while(cin >> maxStep && maxStep != -1) { init(); search(); } return 0;}
0 0
- 1151. 魔板
- 1151. 魔板
- Sicily 1151. 魔板
- 1151. 魔板[Speical judge]
- Sicily 1151. 魔板
- [sicily online]1151. 魔板
- 1151. 魔板[Speical judge]
- Sicily 1151. 魔板
- SOJ 1151. 魔板
- Sicily 1151. 魔板
- Sicily 1151. 魔板
- [sicily]1151. 魔板
- Sicily 1151. 魔板[Speical judge]
- [sicily]1151. 魔板[Special judge]
- [sicily]1151. 魔板[Special judge]
- sicily 1150. 简单魔板 & 1151. 魔板
- 1151. 魔板(用set判重)
- 1151. 魔板(BFS+康托展开式)
- windows编程学习笔记(4)GDI绘图
- poj 2353 类似数塔(需标记路径)
- 第9周项目3(3)-输出星号图
- 第9周项目6-穷举法解决组合问题之百钱百鸡问题
- 仿鲁大师界面(实现启动动画和TabHost选项卡切换时滑动动画)
- 1151. 魔板
- 二维码生成和下载实例
- 关于android·图片处理的集锦贴
- Date类和Math
- 我的第一个oc程序
- Progurd详解
- fzu 2136 取糖果(线段树)
- Android客户端与服务器端通过DES加密认证
- android里发送邮件mail的几种方式