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. Git 使用初体验

    http://my.oschina.net/moooofly/blog/228608 很久之前在 http://git.oschina.net/ 上创建了一个私有项目 modb ,目的主要是用来学习如 ...

  2. nat和打洞

    http://michankong.blog.51cto.com/1464983/761270 可能有点乱,下面以故事的形式叙述一下这个情景. 人物:A(男) NAT_A(A家接线员) B(女) NA ...

  3. 利用线程把文本文件填充到richTextBox;防止导入大文本文件窗口假死现象

    private void btnDr_Click(object sender, EventArgs e) { richTextBox1.Text = ""; //richTextB ...

  4. 条形图(diagrams)

    条形图(diagrams) 题目描述 小 虎刚上了幼儿园,老师让他做一个家庭作业:首先画3行格子,第一行有3个格子,第二行有2个格子,第三行有3个格子.每行的格子从左到右可以放棋子,但要 求除第一行外 ...

  5. 关于Application.Lock…Application.Unlock有什么作用?

    因为Application变量里一般存储的是供所有连接到服务器的用户共享的信息(就像程序中所说的 "全局变量 "), 由于是全局变量,所以就容易出现两个或者多个用户同时对这一变量进 ...

  6. Scroll View 深入

    转载自:http://mobile.51cto.com/hot-430409.htm 可能你很难相信,UIScrollView和一个标准的UIView差异并不大,scroll view确实会多一些方法 ...

  7. HDU 1815 Building roads

    二分答案 + 2-SAT验证 POJ 稳过,HDU C++ 超时,G++ 550ms左右AC #include<cstdio> #include<cstring> #inclu ...

  8. 笔记整理--HTTP Header 详解

    HTTP Header 详解 2013/09/21 | 分类: IT技术 | 0 条评论 | 标签: HTTP 分享到:36 原文出处: zcmhi HTTP(HyperTextTransferPro ...

  9. Java ZIP压缩和解压缩文件并兼容linux

    JDK中自带的ZipOutputStream在压缩文件时,如果文件名中有中文,则压缩后的 zip文件打开时发现中文文件名变成乱码. 解决的方法是使用apache-ant-zip.jar包(见附件)中的 ...

  10. 深入理解setTimeout的作用域

    看了一篇关于setTimeout作用域的问题,其实之前在<javascript高级程序设计>时也看到了,分享给大家: 先总结下: 一.setTimeout中的延迟执行代码中的this永远都 ...