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 ...
随机推荐
- ActiveMQ(5.10.0) - Wildcards and composite destinations
In this section we’ll look at two useful features of ActiveMQ: subscribing to multiple destinations ...
- jQuery之对话框
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...
- Javascript之改变盒子颜色
index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- SQL_insert into(把B表某些字段,插入A表某些字段)
insert into table_A([column],[column],[column]) select column,column,columnfrom table_Bwhere ...orde ...
- js 后台弹窗
后台弹出操作成功,失败信息 /// <summary> /// 弹出信息,并跳转指定页面. /// </summary> public static void AlertAnd ...
- iOS动画——文字晃动
比如密码错误提示,需要文字左右晃动几次,以起到警示的作用. 为了调用使用方便,做一个分类.代码如下: .h文件 #import <QuartzCore/QuartzCore.h> @int ...
- UIView-4-EventForViews(在view上加入button时候的事件处理)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- [zz] 安装PostGIS(Linux篇)
0.安装PostgreSQL数据库 参考安装PostgreSQL数据库(Linux篇). 1.安装proj4 #tar zxvf proj-4.8.0.tar.gz#cd proj-4.8.0#./c ...
- (POJ 3026) Borg Maze 最小生成树+bfs
题目链接:http://poj.org/problem?id=3026. Description The Borg is an immensely powerful race of enhanced ...
- OpenCV和Matplotlib色彩空间模式不一致的问题
当用OpenCV读取彩色图像时,OpenCV是以(BGR)的顺序存储图像数据的,而Matplotlib是以(RGB)的顺序显示图像的. 可以用下面的程序来证明这一点 import cv2 import ...