所谓“周界搜索”,练习搜索的好题,双向宽搜/迭代加深均可,还有很多细节有待完善,判重有比set更优的结构,宽搜还没写,先存一下。

//Writer:GhostCai && His Yellow Duck

#include<iostream>
#include<string>
#include<set>
#include<queue>
using namespace std; set<string> book;
set<string> ans;
bool flag;
string tar="034305650121078709X90";
string st,tmp,sr;
int n; void change(int way,string &r){
char sav;
int i;
switch(way){
case 1:
sav=r[11];
for(i=11;i>=1;i--) r[i]=r[i-1];
r[0]=sav;
break;
case 2:
sav=r[0];
for(i=0;i<=10;i++) r[i]=r[i+1];
r[11]=sav;
break;
case 3:
sav=r[9];
for(i=9;i<=19;i++) r[i]=r[i+1];
r[20]=sav;
break;
case 4:
sav=r[20];
for(i=20;i>=10;i--) r[i]=r[i-1];
r[9]=sav;
break;
} } void make(int dp,int mxdp){
if(dp>mxdp) return;
cout<<tar<<endl;
string pre;
for(int i=1;i<=4;i++){
pre=tar;
change(i,tar);
if(!ans.count(tar)) {
ans.insert(tar);
make(dp+1,mxdp);
}
tar=pre;
}
} void dfs(int dp,int mxdp){
if(dp>mxdp) return;
if(flag) return;
if(ans.count(tmp)){
flag=1;
return;
}
if(book.count(tmp) ) return;
// cout<<tmp<<endl;
int i;
string pre;
for(i=1;i<=4;i++){
pre=tmp;
change(i,tmp); //
dfs(dp+1,mxdp);
book.insert(tmp); tmp=pre;
}
} bool read_s(){
int s;
for(int i=1;i<=24;i++){
cin>>s;
if(i>=22) continue;
if(s==10) st+='X' ;
else st+=char('0'+s);
}
return true;
} int main(){
make(1,8);
cin>>n;
for(int i=1;i<=n;i++){
// read_s();
cin>>st;
// cout<<st<<endl;
if(st==tar) {
cout<<"PUZZLE ALREADY SOLVED\n";
st="";
continue;
}
tmp=st;
flag=0;
for(int i=1;i<=8;i++){
dfs(1,i);
if(flag){
cout<<i<<endl;
break;
}
}
if(!flag) cout<<"NO SOLUTION WAS FOUND IN 16 STEPS\n";
st="";
} }

[UVA] 704 Colour Hash的更多相关文章

  1. uva 704

    自己之前的不见了.. 这题是双向广搜即可过.. // Colour Hash (色彩缤纷游戏) // PC/UVa IDs: 110807/704, Popularity: B, Success ra ...

  2. uva 6959 Judging hash

    Judging Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem/viewProb ...

  3. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  4. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  5. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  6. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  7. UVa 10029 hash + dp

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA 10798 - Be wary of Roses (bfs+hash)

    10798 - Be wary of Roses You've always been proud of your prize rose garden. However, some jealous f ...

  9. UVA 257 - Palinwords(弦HASH)

    UVA 257 - Palinwords 题目链接 题意:输出一个文本里面的palinword,palinword的定义为.包括两个不同的回文子串,而且要求回文子串不能互相包括 思路:对于每一个单词推 ...

随机推荐

  1. export default 和 export 的使用方式(六)

    一:ES6 的导入模块方式和暴露对象方式: ES6 中导入模块使用:import 模块名称 from '模块标识符':import '表示路径': 在 ES6 中使用 export default 和 ...

  2. redis连接错误

    连接redis错误:ERR Client sent AUTH, but no password is set 2018-07-04 20:33 by robinli, 4367 阅读, 0 评论, 收 ...

  3. B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

    前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...

  4. java实现打印正三角,倒三角

    正三角代码: package BasicType; /** * 封装一个可以根据用户传入值来打印正三角的方法 * @author Administrator */ public class Enme ...

  5. Zynq7000开发系列-5(OpenCV开发环境搭建:Ubuntu、Zynq)

    操作系统:Ubuntu14.04.5 LTS 64bit OpenCV:OpenCV 3.1.0.opencv_contrib gcc:gcc version 4.8.4 (Ubuntu 4.8.4- ...

  6. jq解析xml

    注意:url路径不能用相对路径,需要加入http协议

  7. django (一) 环境的配置及Django文件简介

    1, 创建虚拟环境(virtualenv 和virtualenvwrapper) 1.1, virtualenv的概述 virtualenv是用来创建Python的虚拟环境的库,虚拟环境能够独立于真实 ...

  8. 关于java中的不可变类(转)

    如何在Java中写出Immutable的类? 要写出这样的类,需要遵循以下几个原则: 1)immutable对象的状态在创建之后就不能发生改变,任何对它的改变都应该产生一个新的对象. 2)Immuta ...

  9. 转 【推荐】 RAC 性能优化全攻略与经典案例剖析

    https://mp.weixin.qq.com/s?__biz=MjM5MDAxOTk2MQ==&mid=2650277038&idx=1&sn=05cce57a1d253c ...

  10. [在读] javascript权威指南第六版

    耽搁了有大半年没看,记得当时看到5分之2了吧.权威指南是不管读几遍都能觉得有新收获的书^^