HDU 1813 Escape from Tetris
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的更多相关文章
- HDU 1813 Escape from Tetris (IDA*)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1813 题意:给你一个n*n的迷宫,其中0代表有一个人在这个位置,1代表墙,现在要求一个路线,使所有的人通 ...
- 【HDOJ】1813 Escape from Tetris
bfs预处理一点到边界的最小距离,IDA*求出可行方案.注意按字典序初始化dir数组.并且存在中间点全为1,边界含0的可能性(wa了很多次).此时不输出任何命令. /* 1813 */ #includ ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- HDU 3605 Escape (网络流,最大流,位运算压缩)
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- hdu 1811 Rank of Tetris - 拓扑排序 - 并查集
自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球Tetris高手排行榜, ...
- hdu 1813(IDA*)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1813 思路:首先bfs预处理出‘0’到边界点最短距离,然后构造 h() 为所’0‘点逃离迷宫的最少步数 ...
随机推荐
- PAT (Advanced Level) 1095. Cars on Campus (30)
模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...
- java下发电子邮件demo
在实际项目中会遇到需要使用邮件注册,或者是使用邮件找回密码等操作,需要使用到邮件发送功能. 其实邮件的发送主要是依赖于邮件协议,只要能实现邮件协议,那么发送邮件其实还是很容易的.这一步java类库已经 ...
- PHP学习笔记之数组篇
摘要:其实PHP中的数组和JavaScript中的数组很相似,就是一系列键值对的集合.... 转载请注明来源:PHP学习笔记之数组篇 一.如何定义数组:在PHP中创建数组主要有两种方式,下面就让我 ...
- Itext简绍及操作PDF文件
iText简介 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转 ...
- Mysql中int(2)和int(10)的区别
int(N)中的N不是限制字段取值范围的,int的取值范围是固定的(0至4294967295)或(-2147483648至2147483647) 那么N这个值是为了在字段中的值不够时补零的,但是必须含 ...
- CentOS 系统中安装postfix+dovecot+openwebmail <转>
一.先卸载sendmain[root@ser ~]# yum remove sendmail 二.安装postfix ,dovecot,cyrus-sasl[root@ser ~]# yum -y ...
- 扩展欧几里得 POJ 1061
感觉这道题目的数据好水啊...我的代码我都觉得姿势特别奇怪...竟然还过了... 好吧,原来不是姿势奇怪,而是逆元需要用的时候是余数也需要的时候,这里的余数是不需要的,所以就AC了 就说一下碰到的问题 ...
- 模态对话框 bootstrap-modal.js
调用方式 通过data属性 无需编写JavaScript代码即可生成一个对话框.在一个主控元素,例如按钮,上设置data-toggle="modal",然后再设置data-targ ...
- Linux基本命令之用户系统相关命令
1.格式说明 [simon@localhost simon]$ [simon@localhost ~]$ 这两种方式表示相同.simon是指定用户,localhost是计算机名字,如果不设置默认为lo ...
- Flocker 做为后端存储代理 docker volume-driver 支持
docker Flocker https://github.com/ClusterHQ/flocker/ 文档: https://docs.clusterhq.com/en/latest/docker ...