由于一开始考虑的很不周到,找到很多bug.....越改越长,不忍直视。 不是写模拟的料......................

反正撞墙或者碰到已经走过的点就会转向,转向后还碰到这两种情况就会傻站那不动了......

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <climits>//形如INT_MAX一类的
#define MAX 1111 using namespace std; int vis1[MAX][MAX];
int vis2[MAX][MAX];
int step1[MAX][MAX];
int step2[MAX][MAX];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
struct node {
int x,y,dir,kind;
} q[1011111],st,end,ans,stop;
int head,tail,n,yes;
int flag1 , flag2; bool inside(int x,int y) {
if(x >= 0 && x < n && y >= 0 && y < n) return true;
return false;
} bool ok(int x,int y,int kind) {
if(kind == 1 && vis1[x][y] == 0) return true;
if(kind == 2 && vis2[x][y] == 0) return true;
return false;
} void init() {
memset(vis1,0,sizeof(vis1));
memset(vis2,0,sizeof(vis2));
memset(step1,-1,sizeof(step1));
memset(step2,-1,sizeof(step2));
head = 0;
tail = 0;
yes = 0;
flag1 = 0;
flag2 = 0;
stop.x = -1;
stop.y = -1;
} void getstop(node t,node tt) {
stop.x = t.x;
stop.y = t.y;
if(tt.kind == 1) flag1 = 1,stop.kind = 1;
if(tt.kind == 2) flag2 = 1,stop.kind = 2;
} void bfs() {
vis1[st.x][st.y] = 1;
vis2[end.x][end.y] = 1;
step1[st.x][st.y] = 0;
step2[end.x][end.y] = 0;
q[head++] = st;
q[head++] = end;
while(head != tail) {
node t = q[tail++];
//cout << t.x << ' ' << t.y << endl;
if(step1[t.x][t.y] == step2[t.x][t.y] && step1[t.x][t.y] != -1) {
ans.x = t.x;
ans.y = t.y;
yes = 1;
return ;
}
if(t.x == stop.x && t.y == stop.y && t.kind != stop.kind) {
ans.x = t.x;
ans.y = t.y;
yes = 1;
return ;
}
if(flag1 == 1 && flag2 == 1) {
ans.x = -1;
return ;
}
node tt = t;
tt.x = t.x + dx[t.dir];
tt.y = t.y + dy[t.dir]; if(inside(tt.x,tt.y)) {
if(ok(tt.x,tt.y,tt.kind)) {
if(tt.kind == 1) vis1[tt.x][tt.y] = 1, step1[tt.x][tt.y] = step1[t.x][t.y] + 1;
if(tt.kind == 2) vis2[tt.x][tt.y] = 1, step2[tt.x][tt.y] = step2[t.x][t.y] + 1;
q[head++] = tt;
} else {
if(tt.kind == 1) {
if(tt.dir == 3) tt.dir = 0;
else tt.dir ++;
tt.x = t.x + dx[tt.dir];
tt.y = t.y + dy[tt.dir];
if(vis1[tt.x][tt.y] == 0) {
vis1[tt.x][tt.y] = 1;
step1[tt.x][tt.y] = step1[t.x][t.y] + 1;
q[head++] = tt;
} else getstop(t,tt); }
if(tt.kind == 2) {
if(tt.dir == 0) tt.dir = 3;
else tt.dir --;
tt.x = t.x + dx[tt.dir];
tt.y = t.y + dy[tt.dir];
if(vis2[tt.x][tt.y] == 0) {
vis2[tt.x][tt.y] = 1;
step2[tt.x][tt.y] = step2[t.x][t.y] + 1;
q[head++] = tt;
} else getstop(t,tt);
}
}
} else {
if(tt.x < 0) {
if(tt.kind == 1) {
tt.dir = 0;
tt.x = t.x + dx[0];
tt.y = t.y + dy[0];
} else {
tt.dir = 2;
tt.x = t.x + dx[2];
tt.y = t.y + dy[2];
}
} else if(tt.x >= n) {
if(tt.kind == 1) {
tt.dir = 2;
tt.x = t.x + dx[2];
tt.y = t.y + dy[2];
} else {
tt.dir = 0;
tt.x = t.x + dx[0];
tt.y = t.y + dy[0];
}
} else if(tt.y < 0) {
if(tt.kind == 1) {
tt.dir = 3;
tt.x = t.x + dx[3];
tt.y = t.y + dy[3];
} else {
tt.dir = 1;
tt.x = t.x + dx[1];
tt.y = t.y + dy[1];
}
} else if(tt.y >= n) {
if(tt.kind == 1) {
tt.dir = 1;
tt.x = t.x + dx[1];
tt.y = t.y + dy[1];
} else {
tt.dir = 3;
tt.x = t.x + dx[3];
tt.y = t.y + dy[3];
}
}
if(inside(tt.x,tt.y)) {
if(ok(tt.x,tt.y,tt.kind)) {
if(tt.kind == 1) vis1[tt.x][tt.y] = 1, step1[tt.x][tt.y] = step1[t.x][t.y] + 1;
if(tt.kind == 2) vis2[tt.x][tt.y] = 1, step2[tt.x][tt.y] = step2[t.x][t.y] + 1;
q[head++] = tt;
} else getstop(t,tt); } else getstop(t,tt);
}
}
} int main() {
while(scanf("%d",&n) && n) {
init();
scanf("%d%d%d",&st.x,&st.y,&st.dir);
st.kind = 1;
scanf("%d%d%d",&end.x,&end.y,&end.dir);
end.kind = 2; bfs();
if(ans.x == -1 || yes == 0) {
printf("-1\n");
} else {
printf("%d %d\n",ans.x,ans.y);
}
}
return 0;
}

HDU 4740 The Donkey of Gui Zhou (模拟)的更多相关文章

  1. hdu 4740 The Donkey of Gui Zhou bfs

    The Donkey of Gui Zhou Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproble ...

  2. hdu 4740 The Donkey of Gui Zhou(dfs模拟好题)

    Problem Description There was no donkey ,) , the down-right cell ,N-) and the cell below the up-left ...

  3. hdu 4740 The Donkey of Gui Zhou(暴力搜索)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...

  4. hdu 4740 The Donkey of Gui Zhou

    1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...

  5. The Donkey of Gui Zhou

    Problem Description There was no donkey in the province of Gui Zhou, China. A trouble maker shipped ...

  6. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

  7. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  8. HDU 4740 模拟题意

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711743 题意:驴和老虎在方格中跑,跑的方式:径直跑,若遇到边界或之前走过的 ...

  9. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

随机推荐

  1. php不同形式的实现a-z的26个字母的输出

    直接上代码: for($i=ord('a'), $n=ord('z'); $i<=$n; $i++){ echo chr($i),PHP_EOL; } echo PHP_EOL; $char = ...

  2. 无线功率 mW 和 dBm 的换算

    无线电发射机输出的射频信号,通过馈线(电缆)输送到天线,由天线以电磁波形式辐射出去.电磁波到达接收地点后,由天线接收下来(仅仅接收很小很小一部分功率),并通过馈线送到无线电接收机.因此在无线网络的工程 ...

  3. [原]命令模式在MVC框架中的应用

    其实在项目开发中,我们使用了大量的设计模式,只是这些设计模式都封装在框架中了,如果你想要不仅仅局限于简单的使用,就应该深入了解框架的设计思路. 在MVC框架中,模式之一就是命令模式,先来看看模式是如何 ...

  4. 发布MFC ActiveX控件并实现自动更新

    一.        引言 上一篇我们讲了如何使用 VC 2005来开发 MFC ActiveX控件,我们开发 ActiveX控件最终目的是将 ActiveX控件发布出来并嵌入在 Web网页中,随着控件 ...

  5. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(九)

    目的 1. 使用verilog/vhdl设计一个PCI的watchdog设备. 2. 通过systemverilog 写testbench. 很久之前研究过AC97的verilog代码.但是很久没用v ...

  6. _.remove的用法

    var array = [1, 2, 3, 4]; var evens = _.remove(array, function(n) { return n % 2 == 0; }); console.l ...

  7. Saiku图表导出时中文显示问题的解决方法

    Saiku图表导出时png,jpg,pdf三种格式的中文显示都有问题,目前找到一种不太完善的解决方法(中文可以显示但不清晰),需要修改Saiku项目下的ExporterResource.java文件, ...

  8. I Hate It(线段树)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. hdu 2102 A计划(双层BFS)(具体解释)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  10. python <tab>自动补全

    1.获取python目录[我使用的是64位ubuntu系统] [~$]python Python 2.7.3 (default, Apr 10 2013, 06:20:15) [GCC 4.6.3] ...