The Roatin Games poj
来源:互联网 发布:网络电影播放器排行榜 编辑:程序博客网 时间:2024/06/05 07:52
*************************************************************************************************************************************************************************
预计用时:60minutes 实际用时:4200minutes
*************************************************************************************************************************************************************************
题目的知识点:
IDA*算法
形成时间差的原因:
(1) 没有从根本上分清题目的要求和主次
(2) 没有真正的理解解决该题目的思想
(3) 代码实现能力比较弱
(4) 思路混乱
分析该题目
分为3点
(1) 用1维数组来存储整个图,然后用二维数组来存储操作时是对一位数组的数据进行怎样操作的。
(2) 每次深度加1,暴力枚举每一层出现的问题。
(3) 利用估计函数进行剪枝操作(每次操作最多会对影响中间那8个数据中的一个种类)
思路变化成代码
(1) 估计函数
(2) 深度优先函数
(3) 深度的全局变量,步骤的存储方式
代码如下:
#include<iostream>
#include<cstdio>
using namespace std;
int min(int a,int b)
{
returna<b?a:b;
}
int ac[8][7]={
{1,3, 7, 12, 16, 21, 23}, // A 这一列的数字在输入数组中的下标下标从1开始
{2, 4, 9, 13, 18, 22, 24}, // B 这一列的数字在输入数组中的下标 下标从1开始
{11, 10, 9, 8, 7, 6, 5},
{20, 19, 18, 17, 16, 15, 14},
{24, 22, 18, 13, 9, 4, 2},
{23, 21, 16, 12, 7, 3, 1},
{14, 15, 16, 17, 18, 19, 20},
{5, 6, 7, 8, 9, 10, 11}
};
int A[30];
int step[100];
int st;
int maxH;
int check()
{
inttc[4]={0,0,0,0};
tc[A[7]]++; tc[A[8]]++; tc[A[9]]++;
tc[A[12]]++; tc[A[13]]++; tc[A[18]]++;
tc[A[16]]++; tc[A[17]]++;
return min(8-tc[1],min(8-tc[2],8-tc[3]));
}
bool dfs()
{
int i,j;
int n=check();
if(!n)
return true;
if(maxH-st<n)//最少步骤大于最深步骤,返回
return false;
for(i=0;i<8;i++)
{
step[st++]=i;
int temp=A[ac[i][0]];
for(j=0;j<6;j++)
{
A[ac[i][j]]=A[ac[i][j+1]];
}
A[ac[i][6]]=temp;
if(dfs()==true)
return true;
st--;
temp=A[ac[i][6]];
for(j=6;j>0;j--)
{
A[ac[i][j]]=A[ac[i][j-1]];
}
A[ac[i][0]]=temp;
}
return false;//就是这个东西,坑了我一下午。。。
}
int main()
{
//freopen("in.txt","r",stdin);
inti;
while(scanf("%d",&A[1]),A[1])
{
for(i=2;i<25;i++)
scanf("%d",&A[i]);
if(check()==0)
{ printf("No moves needed\n");
printf("%d\n",A[7]);
continue;
}
st=0;
maxH=1;
while(dfs()==false)
maxH++;
for(i=0;i<st;i++)
printf("%c",step[i]+'A');
printf("\n%d\n",A[7]);
}
return0;
}
- The Roatin Games poj
- POJ-1753 flip games
- poj 2138 Travel Games
- POJ 2138 Travel Games
- The Olympic Games 奥林匹克运动会
- The Frog's Games
- The Olympic Games
- The Frog's Games
- The Frog's Games
- The Frog's Games
- poj 3258 River Hopscotch 【二分查找】(The Frog's Games 相似题)
- POJ 1487 Single-Player Games
- POJ 2138 Travel Games 笔记
- POJ 2633 Funny Games 笔记
- the history of video games
- The Frog's Games 二分
- hdu4004 The Frog's Games
- The Frog's Games<hdoj4004>
- Ubuntu 安装mysql和简单操作
- CS224d Problem set 2作业
- 如何实时查看linux下的日志
- uva 673 Parentheses Balance
- 1078. Hashing (25)
- The Roatin Games poj
- 一笔画问题 NYOJ
- Java字符串题目--删除给定字符串中出现次数最少的字符
- 黑马程序员---description方法
- 103. Binary Tree Zigzag Level Order Traversal
- Palindrome Number
- Cow Exhibition 解题报告
- hbase通过row key 的前缀查询记录
- 2015 ICL, Finals, Div. 1 Ceizenpok’s formula(组合数取模,扩展lucas定理+中国剩余定理)