hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址: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(暴力搜索)的更多相关文章
- 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 ...
- 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 ...
- hdu 4740 The Donkey of Gui Zhou
1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...
- HDU 4740 The Donkey of Gui Zhou (模拟)
由于一开始考虑的很不周到,找到很多bug.....越改越长,不忍直视. 不是写模拟的料...................... 反正撞墙或者碰到已经走过的点就会转向,转向后还碰到这两种情况就会傻站 ...
- The Donkey of Gui Zhou
Problem Description There was no donkey in the province of Gui Zhou, China. A trouble maker shipped ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- [HDU 1427]速度计算24点(DFS暴力搜索)
主题连接: pid=1427">http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路:简单的DFS.dfs(sum,next,p)表 ...
- HDU 5444 Elven Postman (二叉树,暴力搜索)
题意:给出一颗二叉树的先序遍历,默认的中序遍历是1..2.……n.给出q个询问,询问从根节点出发到某个点的路径. 析:本来以为是要建树的,一想,原来不用,其实它给的数是按顺序给的,只要搜结点就行,从根 ...
- HDU 3699 A hard Aoshu Problem (暴力搜索)
题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...
随机推荐
- C# 实现远程控制软件的关键技术
一.服务器端多线程Socket技术 用TcpListener进行侦听,接受客户端连接,有客户端连进来后开启处理线程处理数据,代码如下: using System; using System ...
- Spring(3.2.3) - Beans(7): 延迟实例化
默认情况下,Spring IoC 容器启动后,在初始化过程中,会以单例模式创建并配置所有使用 singleton 定义的 Bean 的实例.通常情况下,提前实例化 Bean 是可取的,因为这样在配置中 ...
- Lombok(1.14.8) - @NonNull
@NonNull @NonNull,生成一个非空检查. package com.huey.lombok; import lombok.Getter; import lombok.NonNull; im ...
- django 学习-5 模板使用流程
首先在模板下建一个index.html <!DOCTYPE html><html><head><meta charset="utf-8" ...
- iPad accessory communication through UART
We manufacture a new accessory for iPad/iPhone which should transfer commands to the iPad. We like t ...
- 【转】Android属性之build.prop,及property_get/property_set
简要分析一下build.prop是如何生成的.Android的build.prop文件是在Android编译时收集的各种property(LCD density/语言/编译时间, etc.),编译完成 ...
- des算法的C#实现
DES是Data Encryption Standard(数据加密标准)的缩写.它是一种通过56位密钥来加密64位数据的方法. public class EncryptUtility{ #reg ...
- 开放封闭原则(OCP)
开放封闭原则 转:http://baike.baidu.com/view/2493421.htm转:http://dev.csdn.net/article/38/38826.shtm 开放封闭原则(O ...
- 在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性:
在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性: var s = new MyString("hello"); s ...
- MySQ binlog三种模式
MySQ binlog三种模式及设置方法 1.1 Row Level 行模式 日志中会记录每一行数据被修改的形式,然后在slave端再对相同的数据进行修改 优点:在row level模式下,bin- ...