//第一次在新博客里发文章好紧张怎么办

//MD巨神早已在一个小时前做完了

The Rotation Game
Time Limit: 15000MS Memory Limit: 150000K
Total Submissions: 5950 Accepted: 1992

Description

The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind. 

Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration. 

Input

The input consists of no more than 30 test cases. Each test case has only one line that contains 24 numbers, which are the symbols of the blocks in the initial configuration. The rows of blocks are listed from top to bottom. For each row the blocks are listed from left to right. The numbers are separated by spaces. For example, the first test case in the sample input corresponds to the initial configuration in Fig.1. There are no blank lines between cases. There is a line containing a single `0' after the last test case that ends the input. 

Output

For each test case, you must output two lines. The first line contains all the moves needed to reach the final configuration. Each move is a letter, ranging from `A' to `H', and there should not be any spaces between the letters in the line. If no moves are needed, output `No moves needed' instead. In the second line, you must output the symbol of the blocks in the center square after these moves. If there are several possible solutions, you must output the one that uses the least number of moves. If there is still more than one possible solution, you must output the solution that is smallest in dictionary order for the letters of the moves. There is no need to output blank lines between cases. 

Sample Input

1 1 1 1 3 2 3 2 3 1 3 2 2 3 1 2 2 2 3 1 2 1 3 3 
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 
0 

Sample Output

AC
2
DDHH
2
------------------------------------------------------------------------------------------------------
poj英文题的尿性呵呵哒
大概就是把那个棋盘的abcdef轴旋转次数最少使得中间那几个数字相同(注意只有1,2,3)
那么先找规律,就是把输入数据的位置与abcdef对应
接下来因为搜索层数未知,dfs会TLE,bfs会MLE,所以容易想到ID搜索
先指定递归层数,然后迭代加深一层一层搜下去(有的说用二分但这种小数据反而更费时)
再看每一层的搜索方向
联想八数码问题(然而并不清楚八数码问题),发现每个状态都有最多递归的层数(八个位置贪心减去目前最多的数字个数)
那么写一个估价函数猜猜最多搜多少,如果超出了层数限制那就剪枝,这样就有了IDA*
(我在说些什么)
代码代码代码我要去睡
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #include<limits.h>
 5 int min(int a,int b){
 6     return a<b?a:b;
 7 }
 8 int lines[][]={
 9                    { , , ,,,,},// A
                    { , , ,,,,},// B
                    {, , , , , , },// C
                      {,,,,,,},// D
                    {,,,, , , },//E
                    {,,,, , , },//F
                    {,,,,,,},//G
                    { , , , , , ,},//H
                   };
 int matrix[]={,,,,,,,};
 int cross[];
 char ans[];
 int check(){
     for(int i=;i<;i++)if(cross[matrix[]]!=cross[matrix[i]])return ;
     return ;
 }
 int predict(){
     int most=;
     for(int i=;i<=;i++){
         int a=;
         for(int j=;j<;j++)if(cross[matrix[j]]!=i)a++;
         most=min(most,a);
     }
     return most;
 }
 int rotate(int mode){
     int le=cross[lines[mode][]];
     for(int i=;i<;i++)cross[lines[mode][i]]=cross[lines[mode][i+]];
     cross[lines[mode][]]=le;
     return ;
 }
 int dfs(int dpt,int dptm){
     if(dpt==dptm) return check();
     if(dpt+predict()>dptm) return ;
     for(int i=;i<;i++){
         ans[dpt]=i+'A';
         rotate(i);
         if(dfs(dpt+,dptm)) return ;
         if(i%==)  rotate((i+)%);
         else  rotate((i+)%);
     }
     return ;
 }
 int main(){
     while(scanf("%d",&cross[])!=EOF&&cross[]!=){
           for(int i=;i<;i++) scanf("%d",&cross[i]);
           if(check()) printf("No moves needed\n");
           else{
                int i=;
                while(++i) if(dfs(,i)) break;
                ans[i]='\0';
                printf("%s\n",ans);
           }
           printf("%d\n",cross[matrix[]]);
     }
     return ;
 }

[poj2286]The Rotation Game (IDA*)的更多相关文章

  1. POJ2286 The Rotation Game[IDA*迭代加深搜索]

    The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 6325   Accepted: 21 ...

  2. POJ2286 The Rotation Game(IDA*)

    The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 5691   Accepted: 19 ...

  3. HUD 1043 Eight 八数码问题 A*算法 1667 The Rotation Game IDA*算法

    先是这周是搜索的题,网站:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=6041 主要内容是BFS,A*,IDA*,还有一道K短路的,.. ...

  4. POJ2286 The Rotation Game

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

  5. 7-12 The Rotation Game IDA*

    状态搜索题目  一开始打算用bfs  但是图给的不是矩形图  有点难以下手 参考了 lrj    将图上所有的点进行标号  直接一个一维数组就解决了图的问题  并且明确了每个点的标号  处理起来十分方 ...

  6. hdu 1667 The Rotation Game ( IDA* )

    题目大意: 给你一个“井”子状的board,对称的由24个方块组成,每个方块上有123三个数字中的一个.给你初始状态,共有八种变换方式,求字典序最小的最短的的变换路径使得,board中间的八个方块上数 ...

  7. POJ 2286 The Rotation Game IDA*

    (再一次感谢学长幻灯片) ID A* 随便自己yy了一下. 额嗯 思路什么的都没有问题 就是改不对.. 无奈地删代码...边删边交. 删啊删 哎呦 AC了 ... ... ... 找删的那一段 . o ...

  8. A*专题训练

    POJ2449 Remmarguts' Date UDF's capital consists of N stations. The hall is numbered S, while the sta ...

  9. 启发式搜索——A*算法

    启发式搜索 启发式搜索是一种对搜索到的每一个位置进行评估,然后从评估的最优位置进行搜索直到目的地, 由于搜索时对每一个位置的评估是基于直观或经验的所有叫启发式搜索 A*算法 历史: 1964年Nils ...

随机推荐

  1. grid

  2. Shipyard安装、使用

    Shipyard使用Citadel集群管理工具包,简化对横跨多个主机的Docker容器集群进行管理.通过Web用户界面,你可以大致浏览相关信息,比如你的容器在使用多少处理器和内存资源.在运行哪些容器, ...

  3. java利用zxing编码解码一维码与二维码

    最近琢磨了一下二维码.一维码的编码.解码方法,感觉google的zxing用起来还是比较方便. 本人原创,欢迎转载,转载请标注原文地址:http://wallimn.iteye.com/blog/20 ...

  4. 浮点数转换为人名币读法字符串(JAVA)

    /*<java疯狂讲义>浮点数转换为人名币读法字符串这个用例,感觉没有考虑零的情况*/ import java.util.Arrays; public class Num2Rmb { pr ...

  5. 会话标识未更新(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于会话标识未更新问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ----------------- ...

  6. Andriod 按钮代码

    package com.example.test1; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  7. Fishnet(暴力POJ 1408)

    Fishnet Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1911   Accepted: 1227 Descripti ...

  8. Python3发送post请求,自动记住cookie

    转载自:http://www.cnblogs.com/meitian/p/4607737.html 在做登录的post请求时,需要记住cookie,否则不能访问登录后的页面. 下面是登录的代码: #c ...

  9. Java中通过Selenium WebDriver定位iframe中的元素

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 问题:有一些元素,无论是通过id或是xpath等等,怎么都定位不到. 分析:这很可能是因为你要定位 ...

  10. fzu 2171 防守阵地 II

    Problem 2171 防守阵地 II Accept: 31    Submit: 112Time Limit: 3000 mSec    Memory Limit : 32768 KB  Prob ...