题目

题目

 


 

分析

lrj代码。。。。

还有is_final是保留字,害的我CE了好几发。

 


 

代码

#include <cstdio>
#include <algorithm>
using namespace std; int line[8][7]={
{ 0, 2, 6,11,15,20,22}, // A
{ 1, 3, 8,12,17,21,23}, // B
{10, 9, 8, 7, 6, 5, 4}, // C
{19,18,17,16,15,14,13}, // D
}; const int rev[8] = {5, 4, 7, 6, 1, 0, 3, 2}; // reverse lines of each line // center squares
const int center[8] = {6, 7, 8, 11, 12, 15, 16, 17}; int a[24];
char ans[1000]; bool is__final()
{
for(int i=0;i<8;i++)
if(a[center[i]]!=a[center[0]]) return false;
return true;
} int diff(int target)
{
int ans=0;
for(int i=0;i<8;i++)
if(a[center[i]]!=target) ans++;
return ans;
} inline int h()
{
return min(min(diff(1),diff(2)),diff(3));
} inline void move(int i)
{
int tmp = a[line[i][0]];
for(int j = 0; j < 6; j++) a[line[i][j]] = a[line[i][j+1]];
a[line[i][6]] = tmp;
} bool dfs(int d,int maxd)
{
if(is__final())
{
ans[d]='\0';
printf("%s\n",ans);
return true;
}
if(d+h() > maxd) return false;
for(int i=0;i<8;i++)
{
ans[d]='A'+i;
move(i);
if(dfs(d+1,maxd)) return true;
move(rev[i]);
}
return false;
}
int main()
{
for(int i=4;i<8;i++)
for(int j=0;j<7;j++) line[i][j]=line[rev[i]][6-j]; while(scanf("%d",&a[0])==1 && a[0])
{
for(int i=1;i<24;i++) scanf("%d",&a[i]);
for(int i=0;i<24;i++) if(!a[i]) return 0;
if(is__final()) printf("No moves needed\n");
else
{
for(int maxd=1; ; maxd++)
if(dfs(0,maxd)) break;
}
printf("%d\n",a[6]);
}
return 0;
}

【UVa】1343 The Rotation Game(IDA*)的更多相关文章

  1. 【UVa】11212 Editing a Book(IDA*)

    题目 题目     分析 get一下IDA*的技巧,感觉总体来说不难,主要是剪枝比较难想. 这是lrj的代码,比较通俗易懂,关键就是选定一个区间再取出来,插入到一个位置,接下来转移到这个状态.     ...

  2. 【UVA】10635 Prince and Princess(LCS)

    题目 传送门:QWQ 分析 水题.$ O(nlogn) $的LCS 代码 #include <bits/stdc++.h> using namespace std; *, INF=1e9; ...

  3. 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)

    题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...

  4. 【UVA】12504 Updating a Dictionary(STL)

    题目 题目     分析 第一次用stringstream,真TMD的好用     代码 #include <bits/stdc++.h> using namespace std; int ...

  5. 【BZOJ】1085 [SCOI2005]骑士精神(IDA*)

    题目 传送门:QWQ 分析 我好菜啊. 一波IDA*水过去了. 代码 #include <bits/stdc++.h> using namespace std; ; char s[maxn ...

  6. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  7. 【原】FMDB源码阅读(二)

    [原]FMDB源码阅读(二) 本文转载请注明出处 -- polobymulberry-博客园 1. 前言 上一篇只是简单地过了一下FMDB一个简单例子的基本流程,并没有涉及到FMDB的所有方方面面,比 ...

  8. 【原】FMDB源码阅读(一)

    [原]FMDB源码阅读(一) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 说实话,之前的SDWebImage和AFNetworking这两个组件我还是使用过的,但是对于 ...

  9. 【原】AFNetworking源码阅读(六)

    [原]AFNetworking源码阅读(六) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这一篇的想讲的,一个就是分析一下AFSecurityPolicy文件,看看AF ...

随机推荐

  1. etl工具-Bireme

    前段时间做数据仓库项目,自己实现了一部分etl功能,后面一直没有时间去深入挖掘.这个工具貌似不错,写个帖子做下记录: https://hashdatainc.github.io/bireme/READ ...

  2. jq的attr、prop和data区别

    prop()获取在匹配的元素集中的第一个元素的属性值. 大家都知道有的浏览器只要写disabled,checked就可以了,而有的要写成disabled = "disabled", ...

  3. Nginx 作为反向代理优化要点proxy_buffering

    当nginx用于反向代理时,每个客户端将使用两个连接:一个用于响应客户端的请求,另一个用于到后端的访问: 那么,可以从如下配置起步: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  4. java读取resource/通过文件名获取文件类型

    java读取resource java读取resource目录下文件的方法: 借助Guava库的Resource类 Resources.getResource("test.txt" ...

  5. EasyPlayer RTSP安卓Android播放器架构简析

    本文转自EasyDarwin开源团队成员John的博客:http://blog.csdn.net/jyt0551/article/details/73310641 EasyPlayer 是一款小而美的 ...

  6. EasyRMS录播管理服务器项目实战:windows上开机自启动NodeJS服务

    本文转自EasyDarwin开源团队成员Penggy的博客:http://www.jianshu.com/p/ef840505ae06 近期在EasyDarwin开源团队开发一款基于EasyDarwi ...

  7. [Linux] Boot分区满了的处理方法 The volume "boot" has only 0 bytes disk space remaining

    1.查看系统目前正在用的内核 abby@abby:~$ uname -r ..--generic 2.查看/boot保存的所有内核 abby@abby:~$ ls -lah /boot total 3 ...

  8. Java内存模型的深入理解

    基础 并发编程的模型分类 在并发编程需要处理的两个关键问题是:线程之间如何通信 和 线程之间如何同步. 通信 通信 是指线程之间以何种机制来交换信息.在命令式编程中,线程之间的通信机制有两种:共享内存 ...

  9. c++语言第二次作业

    一题目7-1统计学生成绩 1实验代码 #include<stdio.h> int main(void) { int i,n,grade,A,B,C,D,E; A=B=C=D=E=; sca ...

  10. I.MX6 linux eGalaxTouch 自动获取设备节点

    I.MX6 linux eGalaxTouch 自动获取设备节点 \\\\\\\\\\\\\\-*- 目录 -*-///////////// | 一. 需求: | 二. /proc/bus/input ...