学习心得(code)

superlong@CoreCoder

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

公告

文字可能放在http://blog.csdn.net/superlong100,此处存放代码

常用链接

留言簿(4)

我参与的团队

搜索

  •  

最新随笔

最新评论

  • 1. re: Poj 1279
  • 对于一个凹多边形用叉积计算面积 后能根据结果的正负来判断给的点集的时针方向?
  • --bsshanghai
  • 2. re: Poj 3691
  • 你写的这个get_fail() 好像并是真正的get_fail,也是说fail指向的串并不是当前结点的子串。为什么要这样弄呢?
  • --acmer1183
  • 3. re: HDU2295[未登录]
  • 这个是IDA* 也就是迭代加深@ylfdrib
  • --superlong
  • 4. re: HDU2295
  • 评论内容较长,点击标题查看
  • --ylfdrib
  • 5. re: HOJ 11482
  • 呵呵..把代码发在这里很不错..以后我也试试...百度的编辑器太烂了....
  • --csuft1

阅读排行榜

评论排行榜

Poj上是2286

#include <stdio.h>
#include 
<string.h>

int map[25], deep;
char path[101];
int len; 
bool flag;
int f[8][7= {                                               //状态转移数组 
    { 13712162123 },
    { 
24913182224 },
    { 
111098765 },
    { 
20191817161514 },
    { 
24221813942 },
    { 
23211612731 },
    { 
14151617181920 },
    { 
567891011 }
    };

inline 
int max(int a, int b)
{
return a>b?a:b;}

void out()                                                       //输出路径 
{
    
int i;
    
for(i = 0; i < len; ++ i)
    printf(
"%c",path[i]);
    puts(
"");
    printf(
"%d\n",map[7]);
}

inline 
int cal()                                                 //A* 
{
    
int num[4= {0000};
    num[map[
7]] ++;   num[map[8]] ++;  num[map[9]] ++;
    num[map[
12]] ++;  num[map[13]] ++;
    num[map[
16]] ++;   num[map[17]] ++;  num[map[18]] ++;
    
return 8 - max(max(num[1], num[2]), num[3]);
}

inline 
bool ok()                                                 //判断是否达到目标态 
{
    
int x = map[7], i;
    
if(map[8]^| map[9]^| map[12]^| map[13]^|
       map[
16]^| map[17]^| map[18]^x)
         
return false;
    
return true;
}

int astar;

void dfs(int dep)                                                //IDA*
{
    
int temp[25], J;
    
if(dep == deep) 
    {
        
if(ok()) flag = true;
        
return ;
    }
    
for(int i = 0; i < 8++ i)
    {
        
for(J = 1; J < 25++ J)temp[J] = map[J];
                                                                 
//状态转移 
        for(J = 0; J < 6++ J)
            map[f[i][J]] 
= temp[f[i][J + 1]];
        map[f[i][
6]] = temp[f[i][0]];

        astar 
= cal();
        
if(deep > dep + astar)
        {
            path[len 
++= i + 'A';
            dfs(dep 
+ 1);
            
if(flag)return;
            len 
--;
        }
        
for(J = 1; J < 25++ J)map[J] = temp[J];
    }
}

int main()
{
    
while(scanf("%d"&map[1]), map[1])
    {
        
for(int i = 2; i < 25++ i) scanf("%d"&map[i]);
        
if(ok())
        {
            printf(
"No moves needed\n%d\n", map[7]);
            
continue;
        }
        len 
= 0; deep = 1;
        flag 
= false;
        
while(!flag) 
        {
            dfs(
0);
            deep 
++;
        }
        
out();
    }
}

posted on 2009-09-03 01:21 superlong 阅读(149) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理