HDU 4740 The Donkey of Gui Zhou (模拟)
由于一开始考虑的很不周到,找到很多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 1111using 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;
}
转载于:https://www.cnblogs.com/pangblog/p/3324945.html
HDU 4740 The Donkey of Gui Zhou (模拟)相关推荐
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- HDU 4740——The Donkey of Gui Zhou
题意:驴跟老虎一起走,问什么时候能相遇 题目的意思是在一个地方只能转一次弯..坑了好长时间 代码如下: #include <cstring> #include <stdio.h> ...
- The Donkey of Gui Zhou
原题地址 题意很简单就是驴和老虎在方格中跑,跑的方式:径直跑,若遇到边界或之前走过的点则转向,驴向右转,虎向左转,若转向后还不能跑则一直呆着不动, 问题就是:他们是否会相遇,会输出相遇坐标,不会输出- ...
- 【HDU】5343 MZL's Circle Zhou【后缀自动机】
传送门:[HDU]5343 MZL's Circle Zhou 对于a串可能和b串重复的部分,我们总能找到一个位置,使得a串达到最长,即a串的后继为空,所以我们只要预处理以字符x为开头的b串的个数即可 ...
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- 基于Matlab雷达探测系统(GUI界面模拟)
文件大小:22M 开发环境:Matlab2020 代码行数:490行(主函数)带中文注释 点击下载:点击下载 简要概述:我们的目的是利用MATLAB构建一个模拟模型,通过观察得到显示器上的信号,可以粗 ...
- 超声仿真 matlab,基于Matlab的超声场可视化研究及GUI仿真模拟
谭智源 沈洋 游泳 [摘 要]利用超声场理论及对其数学计算,对常用圆形活塞换能器的声轴线声压分布.轴向横截面的声压分布及声场指向性的理论计算进行推导得出数学函数表达式,再通过Matlab数学软件模拟仿 ...
- 【HDU】4706 Children's Day(模拟)
http://acm.hdu.edu.cn/showproblem.php?pid=4706 该题没有输入,直接输出不同形状大小的N,在输出不同形状N的时候是要用到26个字母,并且是循环输出 #inc ...
- HDU Problem - 6396 Swordsman(优先队列,模拟)
题目链接 Problem Description Lawson is a magic swordsman with kkk kinds of magic attributes v1,v2,v3,-,v ...
最新文章
- java客户姓名添加和查找_java类与对象 演练 客户姓名添加与查看
- java中po代码示例_java操作oracle常用的示例代码详解
- MySQL快速上手[学习笔记](三)
- 论文理解(一)树形lstm
- 将csv文件存入mysql数据库_将csv文件导入到mysql数据库
- 开源电脑屏幕录制软件Captura源码下载及编译(Win10,VS2022)
- Binutils - c++filt工具
- 《Gpu Gems》《Gpu Pro》《Gpu Zen》系列读书笔记
- Clickhouse(20.4.2.9) SSB性能测试
- teamspeak语音服务器价格,语音聊天社交很热门,带你搭建自己的语音聊天服务器...
- 进程管理API之pid_nr/pid_vnr/pid_nr_ns
- 【巴比特:区块链是什么】笔记
- Java Json格式化工具
- 接口监控,系统监控,服务保证
- JavaScript中的Event.target
- 人工智能可以增强学习积极性与投入度,学生学习将更为沉浸
- 【Windows10】电脑双屏后无法调节屏幕亮度?解决方法
- bp神经网络原理 实现过程,bp神经网络的应用案例
- P3964 [TJOI2013]松鼠聚会【切比雪夫距离】
- 玛雅2016 Mac主要功能及使用详解