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 ...
随机推荐
- ORACLE字符串分组聚合函数(字符串连接聚合函数)
ORACLE字符串连接分组串聚函数 wmsys.wm_concat SQL代码: select grp, wmsys.wm_concat(str) grp, 'a1' str from dual un ...
- 每天一道LeetCode--342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- JAVA 基础加强学习笔记
一.面向对象 (一)继承 1.继承的好处: (1) 提高了代码的复用性. (2) 让类与类之间产生了关系,提供了另一个特征多态的前提. 注意: 子类中所有的构造函数都会默认访问父类中的空参数的构造函 ...
- Build Firefox 编译Firefox
准备 选择需要的firefox版本 http://hg.mozilla.org/releases/ 选择最新的build工具 http://ftp.mozilla.org/pub/mozilla.or ...
- WMI查看电脑信息,devenv管理自己的解决方案
最近把公司用的电脑重装了一下,期间用到了驱动精灵,驱动精灵把电脑的全方面信息都显示出来了,让人有种一目了然的感觉,为什么我不自己也写个呢?虽然显示的数据不一定有驱动精灵全单至少是我自己写的,不是吗? ...
- (转)如何在高并发分布式系统中生成全局唯一Id
又一个多月没冒泡了,其实最近学了些东西,但是没有安排时间整理成博文,后续再奉上.最近还写了一个发邮件的组件以及性能测试请看 <NET开发邮件发送功能的全面教程(含邮件组件源码)> ,还弄了 ...
- CCM加密学习
这几天终于搞定了AES硬件加密工具的使用,几种简单的加密模式也都实验通过了,比较麻烦的一种是CCM模式的加密,它是CTR加密模式和CMAC认证算法的混合使用.本文先介绍CCM模式的原理与基本实现,然后 ...
- Poj 2707 Copier Reduction
1.Link: http://poj.org/problem?id=2707 2.Content: Copier Reduction Time Limit: 1000MS Memory Limit ...
- iOS 简单总结:description方法\NSLog函数
1.description方法是NSObject自带的方法,包括类方法和对象方法 + (NSString *)description; // 默认返回 类名 - (NSString *)descrip ...
- 认识HTML5
引言,认识两个标准制定的组织 在讲什么是Html5之前得先了解两个组织:WHATWG :网页超文本技术工作小组(英语:Web Hypertext Application Technology Work ...