题目地址: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. Android中更新视图的函数onDraw()和dispatchdraw()函数的区别

    Android的view组件显示主要经过mesure, layout和draw这三个过程.在mesure阶段里调用mesure(int widthSpec, int heightSpec)方法,这个方 ...

  2. Commons CLI - Option Properties

    Option Properties The following are the properties that each Option has. All of these can be set usi ...

  3. Commons Lang - StringUtils

    Operations on String that are null safe. IsEmpty/IsBlank - checks if a String is empty (判断字符串是否为空) T ...

  4. 【转载】apache kafka系列之-监控指标

    原文地址:http://blog.csdn.net/lizhitao/article/details/24581907 1.监控目标 1.当系统可能或处于亚健康状态时及时提醒,预防故障发生 2.报警提 ...

  5. HDOJ2021发工资咯:)

    发工资咯:) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. 找不到System.Runtime.Serialization.Json的解决方案

    System.ServiceModel System.ServiceModel.Web System.Runtime.Serialization 三者均要添加引用

  7. 【leetcode】10.Regular Expression Matching

    题目描述: Implement regular expression matching with support for '.' and '*'. '.' Matches any single cha ...

  8. c#索引器的简单用法

    abstract class Bird { protected string name; public abstract string Name { get; set; } public abstra ...

  9. UVaLive 3708

    题意:周长为10000的圆上等距分布n个雕塑,求再加入m个雕塑后,为使所有雕塑等距分布所需移动原来n个雕塑的最小总距离. 分析:计算相对距离. #include<cstdio> #incl ...

  10. c# Aes加解密和对象序列化

    aes加解密 public class AesCryptto { private string key = "hjyf57468jhmuist"; private string i ...