题目

题目

 


 

分析

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. Spring报错: org.springframework.beans.factory.support.BeanDefinitionValidationException: Couldn't find an init method named 'init' on bean with name 'car'(待解答)

    在Spring工程里,有一个Car类的bean,Main.java主程序,MyBeanPostProcessor.java是Bean后置处理器. 文件目录结构如下: Car.java package ...

  2. Linux:更改hostname主机名

    更改hostname主机名 查看主机名 hostname 临时更改主机名 hostname youname 更改永久生效主机名 1)更改配置文件 vi /etc/sysconfig/network 2 ...

  3. EasyPusher RTSP推流/EasyRTMP RTMP推流Android安卓摄像头视频偏暗的问题解决方案

    本文转自EasyDarwin团队成员JOHN的博客:http://blog.csdn.net/jyt0551/article/details/75730226 在我们测试EasyPusher/Easy ...

  4. GitHub原来也可以用SVN客户端的.

    不知道是不是自己真的太宅了. 一直以为只能用git client 来clone github工程的.  偶然今日发现还可以用 SVN 来下载的. 果断一试. 太好用了. 这回windows 上不用纠结 ...

  5. Android Studio 默认 debug.keystore , apk打包,keystore.jks文件生成,根据keystore密钥获取SHA1安全码

    参考资料: https://blog.csdn.net/nimasike/article/details/51457229 https://www.cnblogs.com/zhangqie/p/643 ...

  6. [Math]Pi(1)

    数学知识忘地太快,在博客记录一下pi的生成. 100 Decimal places 3.14159265358979323846264338327950288419716939937510582097 ...

  7. 【ci框架学习】控制器-视图

    基础的东西就不写了,网上大把的教程,可以慢慢磨.这里说些要注意的要点. 1.所有控制器都必须间接或者直接继承控制器基类 CI_Controller. 2.文件命名尽量小写,因为ci使用的是pathin ...

  8. does not contain bitcode ShardSDK等三方库

    今天升级了XCode到7.0   重新编译项目出现了下面这些错误提示, ShardSDK/ShareSDK.framework/ShareSDK' does not contain bitcode. ...

  9. BZOJ1017: [JSOI2008]魔兽地图DotR【树形DP】【玄学】

    Description DotR (Defense of the Robots) Allstars是一个风靡全球的魔兽地图,他的规则简单与同样流行的地图DotA (Defense of the Anc ...

  10. SQL夯实基础(八):联接运算符算法归类

    今天主要介绍三个常用联接运算符算法:合并联接(Merge join),哈希联接(Hash Join)和嵌套循环联接(Nested Loop Join).(mysql至8.0版本,都只支持Nested ...