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

【题意】

在这里输入题意

【题解】

迭代加深搜索。
每次抽动操作最多只会让中间那一块的区域离目标的“距离”减少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. node.js状态码

    100——客户必须继续发出请求101——客户要求服务器根据请求转换HTTP协议版本200——交易成功201——提示知道新文件的URL202——接受和处理.但处理未完成203——返回信息不确定或不完整2 ...

  2. COWRUN

    USACO COWRUN 随机化搜索+双重递归调用 题面描述:给出8*N(<=14)组牌,每次按顺序选择8张,FJ可以选择前4张或者后4张,COW从FJ选出的牌中选择前两张或者后两张,然后COW ...

  3. 三种new

    http://www.cnblogs.com/zhuyf87/archive/2013/03/23/2976714.html 第一种是正常的new,它是语言内建的,不能重载. new operator ...

  4. Gonet2 游戏server框架解析之Agent(3)

    客户端消息在Agent中的预处理流程. Agent定义好的三种请求: //api.go var RCode = map[int16]string{ 0: "heart_beat_req&qu ...

  5. IOS的四种数据存储方式及优劣

    IOS有四种经常使用数据存储方式: 第一种方法:用NSUserDefaults存储配置信息 NSUserDefaults被设计用来存储设备和应用的配置信息.它通过一个工厂方法返回默认的.也是最经常使用 ...

  6. php 内置的 html 格式化/美化tidy函数 -- 让你的HTML更美观

    php 内置的 html 格式化/美化tidy函数 https://github.com/htacg/tidy-html5 # HTML 格式化 function beautify_html($htm ...

  7. 调用google翻译

    1. [代码]maven依赖     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <dependency>     <groupId>org.a ...

  8. 慢慢人生路,学点Jakarta基础-深入剖析Java的接口和抽象类

    在java面向对象编程的,抽象类和接口始终存在有疑问的地方,因为两者太多相似有太多不同,在刚开始学习的时候经常弄的不对,使用情景搞混,今天来总结之前学习Java中接口和抽象类的问题. 抽象类 了解:只 ...

  9. 73,QT指针数组实战(指针数组与数组指针)

    //指针数组,每一个指针都是一个MainWindow // MainWindow *w[3][4]; // for(int i=0;i<3;i++) // { // for(int j=0;j& ...

  10. Kinect 开发 —— Kinect for windows SDK

    开发 —— 基本的SDK和Windows 编程技巧(彩色图像视频流,深度图像视频流的采集,骨骼跟踪,音频处理,语音识别API) 深度数据,就是Kinect的精髓和灵魂,很多问题都转换为深度图像的模式识 ...