题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740

【题意】:

  森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次,都会朝着一个方向走,直到这个方向不能走,然后转向,驴只会右转,老虎只会左转,当转过一次之后还是不能往前走,那么它就停下来不再移动了。。。问驴和老虎是否能相遇在一个坐标点。。。

【题解】:

  暴力搜索,模拟过程就能过,不存在超时问题

【code】:

 /*
JudgeStatus:Accepted time:15MS
Memory:4212K codeLenght:2591B
Language:C++ Author:cj
*/
#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std;
#define N 1010 int mark[N][N];
int n; int cx[]={,,,-};
int cy[]={,,-,};
int stop1,stop2;
int x,y,flag; void solve(int r1,int c1,int d1,int r2,int c2,int d2)
{
int x1,y1,x2,y2;
x1=r1;
y1=c1;
x2=r2;
y2=c2;
while()
{
r1=x1,c1=y1,r2=x2,c2=y2;
if(flag) break;
if(!stop1) //判断驴是否已经停止移动
{
x1=r1+cx[d1];
y1=c1+cy[d1];
if(x1>=&&x1<n&&y1>=&&y1<n&&mark[x1][y1]!=&&mark[x1][y1]!=)
{
mark[x1][y1]+=;
}
else
{
d1 = (d1+)%;
x1=r1+cx[d1];
y1=c1+cy[d1];
if(!(x1>=&&x1<n&&y1>=&&y1<n&&mark[x1][y1]!=&&mark[x1][y1]!=))
{
stop1=;
x1=r1;
y1=c1;
}
else
{
mark[x1][y1]+=;
}
}
}
if(!stop2) //判断老虎是否已经停止移动
{
x2=r2+cx[d2];
y2=c2+cy[d2];
if(x2>=&&x2<n&&y2>=&&y2<n&&mark[x2][y2]!=&&mark[x2][y2]!=)
{
mark[x2][y2]+=;
}
else
{
d2 = (d2+)%;
x2=r2+cx[d2];
y2=c2+cy[d2];
if(!(x2>=&&x2<n&&y2>=&&y2<n&&mark[x2][y2]!=&&mark[x2][y2]!=))
{
stop2=;
x2=r2;
y2=c2;
}
else
{
mark[x2][y2]+=;
}
}
}
if(x1==x2&&y1==y2) //当老虎和驴相遇
{
x=x1;
y=y1;
flag=;
return ;
}
if(stop1+stop2==) //当老虎和驴都停止移动且不在同一坐标,返回不可达
{
flag=-;
}
}
} int main()
{
while(~scanf("%d",&n)&&n)
{
int r1,c1,r2,c2,d1,d2;
scanf("%d%d%d",&r1,&c1,&d1);
scanf("%d%d%d",&r2,&c2,&d2);
memset(mark,,sizeof(mark));
flag=stop1=stop2=;
mark[r1][c1]=;
mark[r2][c2]=;
if(r1==r2&&c1==c2)
{
printf("%d %d\n",r1,c1);
continue;
}
solve(r1,c1,d1,r2,c2,d2);
if(flag==-)
{
puts("-1");
}
else
{
printf("%d %d\n",x,y);
}
}
return ;
}

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

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

  4. HDU 4740 The Donkey of Gui Zhou (模拟)

    由于一开始考虑的很不周到,找到很多bug.....越改越长,不忍直视. 不是写模拟的料...................... 反正撞墙或者碰到已经走过的点就会转向,转向后还碰到这两种情况就会傻站 ...

  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 1427 速算24点 dfs暴力搜索

    速算24点 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem De ...

  7. [HDU 1427]速度计算24点(DFS暴力搜索)

    主题连接:  pid=1427">http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路:简单的DFS.dfs(sum,next,p)表 ...

  8. HDU 5444 Elven Postman (二叉树,暴力搜索)

    题意:给出一颗二叉树的先序遍历,默认的中序遍历是1..2.……n.给出q个询问,询问从根节点出发到某个点的路径. 析:本来以为是要建树的,一想,原来不用,其实它给的数是按顺序给的,只要搜结点就行,从根 ...

  9. HDU 3699 A hard Aoshu Problem (暴力搜索)

    题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...

随机推荐

  1. Linux 文件/文件夹操作命令

    1 cd命令 命令格式:cd  [目录名]    (cd和目录之间使用空格隔开) cd      进入用户主目录: cd  ~  进入用户主目录: cd  -  返回进入此目录之前所在的目录: cd  ...

  2. 今天写了几个css属性

    <!DOCTYPE html> <html> <head> <meta charset=UTF-8"> <title></t ...

  3. display:none与visible:hidden区别

    if(list.style.display=='none'){                 list.style.display='block';             }else{       ...

  4. CXF(2.7.10) - RESTful Services, JSON Support

    在 CXF(2.7.10) - RESTful Services 介绍了 REST 风格的 WebService 服务,数据传输是基于 XML 格式的.如果要基于 JSON 格式传输数据,仅需要将注解 ...

  5. Networking - Ethernet II 帧

    Ethernet II 帧格式 DA SA Type Playload FCS DA(Destination Address): 该字段有 6 个字节,表示目的 MAC 地址. SA(Source A ...

  6. kettle学习-day1-介绍、下载、安装

    QQ群:306059317\ 技术支持:荷露叮咚网络学苑http://www.heludd.com/kettle 下载最新版,获取视频教程 kettle安装: 1).下载需要安装的kettle版本,官 ...

  7. Android之图片应用

    package com.example.imagescale; import android.os.Bundle; import android.app.Activity; import androi ...

  8. JSP之Cookie

    Cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器,通过使用cookie可以标识用户身份,记录用户名和密码,跟踪重复等. 首先创建index.jsp: <%@page import ...

  9. SQL通过日期计算年龄

    首先建立一个表如下: ======================= BirthDay datetime not null Age 通过公式计算得出 ======================= 以 ...

  10. js笔记——浏览器及版本判断

    判断IE浏览器的时候注意需要做两个判断 一个是msie 一个是Edge function myBrowser(){ var userAgent = navigator.userAgent; //取得浏 ...