【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

迭代加深搜索。
每次抽动操作最多只会让中间那一块的区域离目标的“距离”减少1.
以这个作为剪枝。
枚举最大深度。
就能过了。

【代码】

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std; const int N = 10; int b[N][N] = { { 1, 3, 7, 12, 16, 21, 23 }, { 2, 4, 9, 13, 18, 22, 24 }, { 11, 10, 9, 8, 7, 6, 5 }, { 20, 19, 18, 17, 16, 15, 14 } };
int fan[N];
int a[30];
int c[N + 5] = { 7, 8, 9, 12, 13, 16, 17, 18 };
int maxdep, ans;
vector <int> v, vans; void init(){
for (int i = 0; i < 4; i++){
int temp;
if (i & 1) temp = 3; else temp = 5;
int j = i + temp;
fan[i] = j;
fan[j] = i;
}
for (int i = 4; i < 8; i++){
int pre = fan[i];
int now = 0;
for (int j = 6; j >= 0; j--){
b[i][now] = b[pre][j];
now++;
}
}
} int ok(){
int mi = 8;
for (int i = 1; i <= 3; i++){
int cnt = 0;
for (int j = 0; j < 8; j++) if (a[c[j]] != i) cnt++;
mi = min(mi, cnt);
}
return mi;
} void Move(int idx){
int temp = a[b[idx][0]];
for (int i = 0; i < 6; i++){
int x = b[idx][i], y = b[idx][i + 1];
a[x] = a[y];
}
a[b[idx][6]] = temp;
} void dfs(int dep){
if (ans != 0) return;
int now = ok();
if (dep == maxdep){
if (now == 0){
vans = v;
ans = a[c[0]];
}
return;
}
int rest = maxdep - dep;
if (rest < now) return;
for (int i = 0; i < 8; i++){
v.push_back(i);
Move(i);
dfs(dep + 1);
v.pop_back();
Move(fan[i]);
}
} int main()
{
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0), cin.tie(0);
init();
while (cin >> a[1] && a[1]){
for (int i = 2; i <= 24; i++) cin >> a[i];
if (ok() == 0){
cout << "No moves needed" << endl;
cout << a[c[0]] << endl;
continue;
} ans = 0;
for (maxdep = 1;; maxdep++){
dfs(0);
if (ans != 0) break;
}
for (int i = 0; i<(int)vans.size(); i++){
cout << (char)(vans[i] + 'A');
}
cout << endl;
cout << ans << endl;
}
return 0;
}

【例 7-12 UVA - 1343】The Rotation Game的更多相关文章

  1. UVa 1343 The Rotation Game (状态空间搜索 && IDA*)

    题意:有个#字型的棋盘,2行2列,一共24个格. 如图:每个格子是1或2或3,一共8个1,8个2,8个3. 有A~H一共8种合法操作,比如A代表把A这一列向上移动一个,最上面的格会补到最下面. 求:使 ...

  2. UVA 1343 The Rotation Game

    题意: 给出图,往A-H方向旋转,使中间8个格子数字相同.要求旋转次数最少,操作序列字典序尽量小. 分析: 用一维数组存24个方格.二维数组代表每个方向对应的7个方格.IDA*剪枝是当8-8个方格中重 ...

  3. UVA - 1343 The Rotation Game (BFS/IDA*)

    题目链接 紫书例题. 首先附上我第一次bfs+剪枝TLE的版本: #include<bits/stdc++.h> using namespace std; typedef long lon ...

  4. UVA 1343 - The Rotation Game-[IDA*迭代加深搜索]

    解题思路: 这是紫书上的一道题,一开始笔者按照书上的思路采用状态空间搜索,想了很多办法优化可是仍然超时,时间消耗大的原因是主要是: 1)状态转移代价很大,一次需要向八个方向寻找: 2)哈希表更新频繁: ...

  5. 【UVa】1343 The Rotation Game(IDA*)

    题目 题目     分析 lrj代码.... 还有is_final是保留字,害的我CE了好几发.     代码 #include <cstdio> #include <algorit ...

  6. UVA_Rotation Game<旋转游戏> UVA 1343

    The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The ...

  7. UVA 1379 - Pitcher Rotation(DP + 贪心)

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=4125" rel="nofo ...

  8. 数据库系统概论(第5版) P262 例8.12

    #include <iostream> #include <stdlib.h> #include <stdio.h> #include <Windows.h& ...

  9. uva 1343 非原创

    uva1343 原作者 题目题意是:给你的棋盘,在A-H方向上可以拨动,问你最少拨动几次可以是中心图案的数字一致 解题思路:回溯法,剪枝 其中要把每次拨动的字母所代表的位置提前用数组表示: 然后在如果 ...

随机推荐

  1. dedecms关键词维护里面字数多的词优先字数少的词的解决办法

    织梦后台的关键词维护默认的情况是字数少的词优先于字数多的词,比如我们有两个这样的词:创业.创业方向,第二个词包含了第一个词,在文章中如果出现“创业方向”这个词,默认情况下只会给创业两个字添加关键词超链 ...

  2. 注解:@SuppressWarning()的用法

    @SuppressWarning() 作用:J2SE 提供的一个批注或者注解.该批注的作用是给编译器一条指令,忽略这些警告信息. 常用:unchecked,serial. 1.如果传入多种情况,这几种 ...

  3. Mysql学习总结(10)——MySql触发器使用讲解

    触发器(TRIGGER)是由事件来触发某个操作.这些事件包括INSERT语句.UPDATE语句和DELETE语句.当数据库系统执行这些事件时,就会激活触发器执行相应的操作.MySQL从5.0.2版本开 ...

  4. hdparm

    https://www.douban.com/note/244813504/ http://blog.sina.com.cn/s/blog_413d250e0101jtr7.html http://m ...

  5. 洛谷—— P1086 花生采摘

    https://www.luogu.org/problem/show?pid=1086#sub 题目描述 鲁宾逊先生有一只宠物猴,名叫多多.这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着 ...

  6. Android捕获View焦点事件,LinearLayout结合HorizontalScrollView实现ViewPgaer和选项卡Tabs联动

     <Android捕获View焦点事件,LinearLayout结合HorizontalScrollView实现ViewPgaer和选项卡Tabs联动.> 如图: package zh ...

  7. es6 --- var const let

    var  const   let  区别 今天第一次遇到const定义的变量,查阅了相关资料整理了这篇文章.主要内容是:js中三种定义变量的方式const, var, let的区别. 1. const ...

  8. 轻松八步搞定Cacti配置安装(原创视频)

    轻松八步搞定Cacti配置安装 1.安装web server $sudo apt-get install apache2 验证 http://localhost 2.$sudo apt-get ins ...

  9. mysql 数据库 存储数据类型

    int 类型的数据  可以在数据库里存成 char字符串类型的数据: 纯数字的字符串 可以在数据库里存储为 int的数据类型.

  10. ManagementObjectSearcher 对象获取串口列表

    首先,需引用using System.Management; 可先建个枚举类,如下 #region WIN32 API /// <summary> /// 枚举win32 api /// ...