The Donkey of Gui Zhou

The donkey lived happily until it saw a tiger far away. The donkey had never seen a tiger ,and the tiger had never seen a donkey. Both of them were frightened and wanted to escape from each other. So they started running fast. Because they were scared, they were running in a way that didn't make any sense. Each step they moved to the next cell in their running direction, but they couldn't get out of the forest. And because they both wanted to go to new places, the donkey would never stepped into a cell which had already been visited by itself, and the tiger acted the same way. Both the donkey and the tiger ran in a random direction at the beginning and they always had the same speed. They would not change their directions until they couldn't run straight ahead any more. If they couldn't go ahead any more ,they changed their directions immediately. When changing direction, the donkey always turned right and the tiger always turned left. If they made a turn and still couldn't go ahead, they would stop running and stayed where they were, without trying to make another turn. Now given their starting positions and directions, please count whether they would meet in a cell.
In each test case:
First line is an integer N, meaning that the forest is a N×N grid.
The second line contains three integers R, C and D, meaning that the donkey is in the cell (R,C) when they started running, and it's original direction is D. D can be 0, 1, 2 or 3. 0 means east, 1 means south , 2 means west, and 3 means north.
The third line has the same format and meaning as the second line, but it is for the tiger.
The input ends with N = 0. ( 2 <= N <= 1000, 0 <= R, C < N)
#include <stdio.h>
#include <string.h>
#define N 1005 bool vis1[N][N];
bool vis2[N][N];
int dir[][]= {,,,,,-,-,};
int T; bool inside(int x,int y)
{
if(x>= &&x<T && y>=&&y<T) return true;
return false;
} int main()
{
int r1,c1,d1,r2,c2,d2;
int x1,y1,x2,y2;
while(scanf("%d",&T),T)
{
memset(vis1,false,sizeof(vis1));
memset(vis2,false,sizeof(vis2));
scanf("%d %d %d",&r1,&c1,&d1);
scanf("%d %d %d",&r2,&c2,&d2); bool ok1 = true,ok2 = true;
bool flag=false;
while()
{
if(r1==r2 && c1==c2)
{
flag = true;
break;
}
if(!ok1 && !ok2) break;
vis1[r1][c1] = true;
vis2[r2][c2] = true;
if(ok1)
{
x1 = r1 + dir[d1][];
y1 = c1 + dir[d1][];
if(inside(x1,y1) && !vis1[x1][y1])
{
r1 = x1;
c1 = y1;
}
else
{
x1 = r1 + dir[(d1+)%][];
y1 = c1 + dir[(d1+)%][];
if(inside(x1,y1) && !vis1[x1][y1])
{
r1 = x1;
c1 = y1;
d1 = (d1+)%;
}
else ok1 = false;
}
}
if(ok2)
{
x2 = r2 + dir[d2][];
y2 = c2 + dir[d2][];
if(inside(x2,y2) && !vis2[x2][y2])
{
r2 = x2;
c2 = y2;
}
else
{
x2 = r2 + dir[(d2+)%][];
y2 = c2 + dir[(d2+)%][];
if(inside(x2,y2) && !vis2[x2][y2])
{
r2 = x2;
c2 = y2;
d2 = (d2+)%;
}
else ok2 = false;
}
}
}
if(flag) printf("%d %d\n",r1,c1);
else puts("-1");
} return ;
}
模拟暴力题(双向广搜)
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(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- HDU 4740 The Donkey of Gui Zhou (模拟)
由于一开始考虑的很不周到,找到很多bug.....越改越长,不忍直视. 不是写模拟的料...................... 反正撞墙或者碰到已经走过的点就会转向,转向后还碰到这两种情况就会傻站 ...
- 2013杭州网络赛C题HDU 4640(模拟)
The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- Android View之用户界面...
PS:Android的控件真的是很多...现在还在忙到控件...也是神了.... 学习内容: 1.Spinner下拉菜单... 2.AutoComplete TextView自动完成文本框... 1. ...
- 微信小程序 自定义组件 多列选择器 对象数组 ObjectArray 自关联 三级联动
使用方法 在 Page.json 注册组件 { "usingComponents": { "address-picker": "/component/ ...
- JAVA GUI编程学习笔记目录
2014年暑假JAVA GUI编程学习笔记目录 1.JAVA之GUI编程概述 2.JAVA之GUI编程布局 3.JAVA之GUI编程Frame窗口 4.JAVA之GUI编程事件监听机制 5.JAVA之 ...
随机推荐
- html5绘制折线图
html5绘制折线图详细代码 <html> <canvas id="a_canvas" width="1000" height="7 ...
- PHP 透明水印生成代码
PHP 透明水印生成代码,需要的朋友可以参考下. 复制代码代码如下: <?php /* * Created on 2010-10-27 * BY QQ542900563 * Copyri ...
- EventLog组件
1.使用EventLog组件读写事件日志 SourceExists方法 确定事件源是否已在本地计算机上注册 DeleteEventSource方法 用于从事件日志中移除应用程序的事件源注册 pri ...
- 史上最全github使用方法:github入门到精通--备用
[初识Github] 首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理 ...
- 如何使一个input文本框随其中内容而变化长度(转)
第一: <input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(t ...
- Portal技术综述
从上世纪八十年代起,随着个人计算机(PC)的发展,企事业单位逐步建立起计算机应用系统来处理传统事务.从简单的单机应用逐步发展到局域网系统,进而建立跨地区垮国家的广域网系统.从单纯的以科学计算和数据管理 ...
- BZOJ 3953 Self-Assembly 解题报告
首先,我们可以先考虑一个暴力一点的算法: 对于任意两个分子,如果它们能以至少一种进行匹配,那么我们就在这两个分子之间连一条边. 然后如果我们能找到一个环,就说明是 unbounded,否则就是 bou ...
- ASP.net Application及Session 的start end 方法总结
经过几天的摸索,试验,今天终于可以将Application及Session对象的Start和End方法做下总结了. Application_start: 第一个访问网站的用户会触发该方法. 通常会在该 ...
- POJ2225+BFS
简单的BFS 1a /* 从起点到终点 */ #include<stdio.h> #include<string.h> #include<stdlib.h> # ...
- nginx server_参数配置总结(转)
转:http://onlyzq.blog.51cto.com/1228/535279 Nginx中的server_name指令主要用于配置基于名称的虚拟主机,server_name指令在接到请求后的匹 ...