题目链接

老虎左拐,老鼠右拐,碰到不能走的拐一次,如果还不能走就停下,自己走过的不能走,求相遇的坐标或-1

一个停下之后,另一个还可以走

#include <cstdio>
#include <cstring>
using namespace std;
#define N 1005
struct node
{
int x,y;
}p[N*N],q[N*N];
int visi[N][N],xy[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int n;
int donkey(int x,int y,int d)
{
int step=1;
while(!visi[x][y]&&x<n&&x>=0&&y<n&&y>=0)
{
p[step].x=x;p[step++].y=y;
visi[x][y]=1;
x=x+xy[d][0];y=y+xy[d][1];
if(visi[x][y]||x<0||x>=n||y>=n||y<0)
{
x=x-xy[d][0];y=y-xy[d][1];
d=(d+1)%4;
x=x+xy[d][0];y=y+xy[d][1];
if(visi[x][y]||x<0||x>=n||y>=n||y<0) break;
} }
return step-1;
} int tiger(int x,int y,int d)
{
int step=1; while(!visi[x][y]&&x<n&&x>=0&&y<n&&y>=0)
{
q[step].x=x;q[step++].y=y;
visi[x][y]=1;
x=x+xy[d][0];y=y+xy[d][1];
if(visi[x][y]||x<0||x>=n||y>=n||y<0)
{
x=x-xy[d][0];y=y-xy[d][1];
d=(d+3)%4;
x=x+xy[d][0];y=y+xy[d][1];
if(visi[x][y]||x<0||x>=n||y>=n||y<0) break;
} }
return step-1;
} int main()
{
int i,j,r1,c1,d1,r2,c2,d2,s1,s2,flag;
while(scanf("%d",&n),n)
{
scanf("%d%d%d",&r1,&c1,&d1);
scanf("%d%d%d",&r2,&c2,&d2);
memset(visi,0,sizeof(visi));
s1=donkey(r1,c1,d1);
memset(visi,0,sizeof(visi));
s2=tiger(r2,c2,d2);
i=1;
flag=0;
while(i<=s1||i<=s2)
{
if(i>s1) {p[i].x=p[i-1].x;p[i].y=p[i-1].y;}
if(i>s2) {q[i].x=q[i-1].x;q[i].y=q[i-1].y;}
if(p[i].x==q[i].x&&p[i].y==q[i].y)
{
printf("%d %d\n",p[i].x,p[i].y);
flag=1;
break;
}
i++;
}
if(!flag) printf("-1\n");
/* printf("%d\n",s2); for(i=1;i<=s2;i++)
{
printf("%d %d\n",q[i].x,q[i].y);
}
*/
}
return 0;
}

hdu 4740的更多相关文章

  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(暴力搜索)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...

  3. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  4. 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 ...

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

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

  6. HDU 4740 模拟题意

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711743 题意:驴和老虎在方格中跑,跑的方式:径直跑,若遇到边界或之前走过的 ...

  7. hdu 4740 The Donkey of Gui Zhou

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

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. 数据库sqlite的使用

    #import <Foundation/Foundation.h> @class student; @interface DataBaseHandle : NSObject //设置单例 ...

  2. SQL Server 查看identity值的几种方法。

    方法 1. ident_incr('Table_name');#  增量    identity(A,B) 中的B值 ident_seed('Table_name'); # 种子    identit ...

  3. Oracle EBS-SQL (BOM-16):检查多层BOM.sql

    select rownum seq_num, lpad(to_char(level), decode(level, 1, 1, level + 1), '.') bom_level, bbm.ASSE ...

  4. linux 命令总结(转载)

    linux 命令总结(转载) 1. 永久更改ip ifconfig eth0 新ip 然后编辑/etc/sysconfig/network-scripts/ifcfg-eth0,修改ip 2.从Lin ...

  5. [分享]源代码&开发手记:SAE应用“车百科” (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, jobs)

    [分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...

  6. bash 学习笔记(一)

    尽量使用printf而不要用echo(echo再不同情况下语义不同) 整数%d,小数后6位%f,科学计数法 %e,16进制 %x 宽度限制 %8s %-15s 正数朝右对齐 负数朝左对齐:%04d\n ...

  7. swift学习二:基本的语法

    声明本文转载自:http://www.cocoachina.com/applenews/devnews/2014/0603/8653.html Swift是什么? Swift是苹果于WWDC 2014 ...

  8. 为什么VS提示SurfFeatureDetector不是cv的成员函数

    surf和sift算法都是在头文件#include <opencv2/features2d/features2d.hpp>中,但在新的opencv版本出来后,如果仍然使用这个头文件就会出现 ...

  9. Android 查看通讯录Contacts是否发生变化

    目的:确定通讯录是否发生变化 根据:參见ContactsContract.RawContacts类中的VERSION常量,该值是仅仅读的,当通讯录发生变化时,都会使该值变化 方法:version值是相 ...

  10. 【十分不错】【离线+树状数组】【TOJ4105】【Lines Counting】

    On the number axis, there are N lines. The two endpoints L and R of each line are integer. Give you ...