TMDTMD

IDA*没跑了。什么是IDA*?

就是迭代深搜+A*估个价。

然而为什么调了一天?

n<=2的时候我输出了东西。。。。

看了一天。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define maxn 15
#define inf 2000000000
using namespace std;
int n,map[maxn][maxn],tot=,dis[maxn][maxn],mx=,ans[maxn*maxn*maxn],d,dr[maxn][maxn];
int dx[]={,,-,,},dy[]={,,,,-};
char s[maxn];
queue <int> q;
struct point
{
int x,y;
point (int x,int y):x(x),y(y) {}
point () {}
}p[maxn*maxn];
bool bnd(int x,int y)
{
if ((x==) || (x==n) || (y==) || (y==n)) return true;
return false;
}
bool judge(int x,int y)
{
if ((x>=) && (x<=n) && (y>=) && (y<=n)) return true;
return false;
}
int bfs(int x,int y)
{
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
dr[i][j]=inf;
while (!q.empty()) q.pop();
dr[x][y]=;q.push(x);q.push(y);
while (!q.empty())
{
int hx,hy;
hx=q.front();q.pop();hy=q.front();q.pop();
if (bnd(hx,hy)) return dr[hx][hy];
for (int i=;i<=;i++)
{
int tx=hx+dx[i],ty=hy+dy[i];
if ((map[tx][ty]) && (dr[tx][ty]==inf) && (judge(tx,ty)))
{
q.push(tx);q.push(ty);
dr[tx][ty]=dr[hx][hy]+;
}
}
}
return inf;
}
int gets_h(point p[])
{
int mx=;
for (int i=;i<=tot;i++) mx=max(mx,dis[p[i].x][p[i].y]);
return mx;
}
point modify(point x,int y)
{
if (bnd(x.x,x.y)) return x;
point now=point(x.x+dx[y],x.y+dy[y]);
if ((!map[now.x][now.y]) || (!judge(now.x,now.y))) return x;
else return now;
}
bool IDA(int deep,point p[])
{
point node[maxn*maxn];
if (gets_h(p)+deep>d) return false;
if (deep==d) return true;
for (int i=;i<=;i++)
{
ans[deep]=i;
for (int j=;j<=tot;j++) node[j]=modify(p[j],i);
if (IDA(deep+,node)) return true;
}
return false;
}
void work()
{
tot=;memset(ans,,sizeof(ans));
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
dis[i][j]=-;
for (int i=;i<=n;i++)
{
scanf("%s",s);
for (int j=;j<=n;j++)
{
if (s[j-]=='') map[i][j]=;
else map[i][j]=;
if ((map[i][j]) && (!bnd(i,j))) p[++tot]=point(i,j);
}
}
if (!tot) return;
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
{
if (!map[i][j]) dis[i][j]=inf;
else
{
if (bnd(i,j)) dis[i][j]=;
else dis[i][j]=bfs(i,j);
mx=max(mx,dis[i][j]);
if (dis[i][j]==inf) {printf("CX_naive\n");return;}
}
}
for (d=;;d++)
{
if (IDA(,p))
{
for (int j=;j<d;j++)
{
if (ans[j]==) printf("east\n");
else if (ans[j]==) printf("north\n");
else if (ans[j]==) printf("south\n");
else if (ans[j]==) printf("west\n");
}
return;
}
}
}
int main()
{
int ret=;
while (scanf("%d",&n)!=EOF)
{
if (ret++) printf("\n");
work();
}
return ;
}

HDU 1813 Escape from Tetris的更多相关文章

  1. HDU 1813 Escape from Tetris (IDA*)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1813 题意:给你一个n*n的迷宫,其中0代表有一个人在这个位置,1代表墙,现在要求一个路线,使所有的人通 ...

  2. 【HDOJ】1813 Escape from Tetris

    bfs预处理一点到边界的最小距离,IDA*求出可行方案.注意按字典序初始化dir数组.并且存在中间点全为1,边界含0的可能性(wa了很多次).此时不输出任何命令. /* 1813 */ #includ ...

  3. ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线

    hdu 1811 Rank of Tetris Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  4. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  5. HDU 3605 Escape (网络流,最大流,位运算压缩)

    HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...

  6. Hdu 3605 Escape (最大流 + 缩点)

    题目链接: Hdu 3605  Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...

  7. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  8. hdu 1811 Rank of Tetris - 拓扑排序 - 并查集

    自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...

  9. hdu 1813(IDA*)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1813 思路:首先bfs预处理出‘0’到边界点最短距离,然后构造 h() 为所’0‘点逃离迷宫的最少步数 ...

随机推荐

  1. asp读取指定目录下的文件名

    bianli(Server.MapPath("/")+"\pic") InStrRev("abcd.jpg", ".") ...

  2. 提升html5的性能体验系列之一避免切页白屏

    窗体切换白屏的现实问题 HTML5的性能比原生差很多,比如切页时白屏.列表滚动不流畅.下拉刷新和上拉翻页卡顿.在低端Android手机上,很多原生App常用的功能和体验效果都很难使用HTML5技术模拟 ...

  3. 彻底搞明白find命令的-mtime参数的含义【转载】

    转自: 彻底搞明白find命令的-mtime参数的含义-goolen-ITPUB博客http://blog.itpub.net/23249684/viewspace-1156932/ 以前一直没有弄明 ...

  4. Mysql命令-求一列字段的总和

    求和命令 mysql> select SUM(price) from order where create_time>'2016-03-12';+------------+| SUM(pr ...

  5. Installation error: INSTALL_FAILED_UID_CHANGED 的解决办法

    出现此问题的原因大多是apk冲突造成,解决的办法如下: 1.  Settings -> Applications, 卸载出现问题的apk,重新安装即可. 2. 如果apk无法卸载,则将apk相关 ...

  6. 转 Android HTTPS详解

    目录(?)[-] 前言 HTTPS原理 SSLTLS协议作用 基本的运行过程 握手阶段的详细过程 客户端发出请求ClientHello 服务器回应ServerHello 客户端回应 服务器的最后回应 ...

  7. 设置HTML表格细边框

    简介:WEB前端|这是关于怎么设置HTML表格细边框的问题,把表格边框设置为细小的线条边框一般我们用表格的时候总会给它个border属性,比如:<tableborder="1" ...

  8. Anroid ListView分组和悬浮Header实现

    Anroid ListView分组和悬浮Header实现 分类: Android2014-01-27 12:26 6585人阅读 评论(13) 收藏 举报 listviewheadersection分 ...

  9. flexpaper二次开发

    1.首先下载FlexPaper的源码.下载地址 2.本人不懂flash,只是百度下,然后自己瞎弄弄的.我用的flash build 4.5 提供个key:1499-4181-9296-6452-299 ...

  10. flex中form表单中子元素之间的距离控制

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.ado ...