首页 技术 正文
技术 2022年11月18日
0 收藏 547 点赞 3,114 浏览 2858 个字

Problem DescriptionThere was no donkey in the province of Gui Zhou, China. A trouble maker shipped one and put it in the forest which could be considered as an N×N grid. The coordinates of the up-left cell is (0,0) , the down-right cell is (N-1,N-1) and the cell below the up-left cell is (1,0)….. A 4×4 grid is shown below:
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. InputThere are several test cases.
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) OutputFor each test case, if the donkey and the tiger would meet in a cell, print the coordinate of the cell where they meet first time. If they would never meet, print -1 instead. Sample Input20 0 00 1 240 1 03 2 00 Sample Output-11 3 Source2013 ACM/ICPC Asia Regional Hangzhou Online

 #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 ;
}

模拟暴力题(双向广搜)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898