HDU 网络赛(杭州赛区)1003 (13.09.15)
2013-09-16 14:20
253 查看
[align=left]Problem Description[/align]
There 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 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.
[align=left]Input[/align]
There 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)
[align=left]Output[/align]
For 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.
[align=left]Sample Input[/align]
2
0 0 0
0 1 2
4
0 1 0
3 2 0
0
[align=left]Sample Output[/align]
-1
1 3
题意:
给出一片森林
在这片森林里, 驴和虎从没见过对方, 因此一见面就吓尿了, 撒腿就跑
0 1 2 3代表四个方向, 没有特殊情况就按初始方向直直跑
不能继续向前了, 驴是只考虑向右, 而虎是只考虑向左
注意, 驴和虎都不能跑自己曾经跑过的地块!
AC代码:
There 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 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.
[align=left]Input[/align]
There 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)
[align=left]Output[/align]
For 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.
[align=left]Sample Input[/align]
2
0 0 0
0 1 2
4
0 1 0
3 2 0
0
[align=left]Sample Output[/align]
-1
1 3
题意:
给出一片森林
在这片森林里, 驴和虎从没见过对方, 因此一见面就吓尿了, 撒腿就跑
0 1 2 3代表四个方向, 没有特殊情况就按初始方向直直跑
不能继续向前了, 驴是只考虑向右, 而虎是只考虑向左
注意, 驴和虎都不能跑自己曾经跑过的地块!
AC代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> int lgrid[1234][1234]; int hgrid[1234][1234]; int t; int success; int lunremove; int hunremove; int ansx, ansy; int main() { while(scanf("%d", &t) != EOF && t) { success = 0; lunremove = 1; hunremove = 1; memset(lgrid, 0, sizeof(lgrid)); memset(hgrid, 0, sizeof(hgrid)); int ltx, lty, htx, hty; int ltd, htd; scanf("%d %d %d", <x, <y, <d); scanf("%d %d %d", &htx, &hty, &htd); while(lunremove == 1 || hunremove == 1) { if(ltx == htx && lty == hty) { success = 1; ansx = ltx; ansy = lty; break; } lgrid[ltx][lty] = 1; hgrid[htx][hty] = 1; if(ltd == 2 && lunremove == 1) { if(lty > 0 && lgrid[ltx][lty-1] != 1) lty = lty - 1; else if(ltx > 0 && lgrid[ltx-1][lty] != 1) { ltx = ltx - 1; ltd = 3; } else lunremove = 0; } else if(ltd == 1 && lunremove == 1) { if(ltx < t-1 && lgrid[ltx+1][lty] != 1) ltx = ltx + 1; else if(lty > 0 && lgrid[ltx][lty-1] != 1) { lty = lty - 1; ltd = 2; } else lunremove = 0; } else if(ltd == 0 && lunremove == 1) { if(lty < t-1 && lgrid[ltx][lty+1] != 1) lty = lty + 1; else if(ltx < t-1 && lgrid[ltx+1][lty] != 1) { ltx = ltx + 1; ltd = 1; } else lunremove = 0; } else if(ltd == 3 && lunremove == 1) { if(ltx > 0 && lgrid[ltx-1][lty] != 1) ltx = ltx - 1; else if(lty < t-1 && lgrid[ltx][lty+1] != 1) { lty = lty + 1; ltd = 0; } else lunremove = 0; } if(htd == 2 && hunremove == 1) { if(hty > 0 && hgrid[htx][hty-1] != 1) hty = hty - 1; else if(htx < t-1 && hgrid[htx+1][hty] != 1) { htx = htx + 1; htd = 1; } else hunremove = 0; } else if(htd == 1 && hunremove == 1) { if(htx < t-1 && hgrid[htx+1][hty] != 1) htx = htx + 1; else if(hty < t-1 && hgrid[htx][hty+1] != 1) { hty = hty + 1; htd = 0; } else hunremove = 0; } else if(htd == 0 && hunremove == 1) { if(hty < t-1 && hgrid[htx][hty+1] != 1) hty = hty + 1; else if(htx > 0 && hgrid[htx-1][hty] != 1) { htx = htx - 1; htd = 3; } else hunremove = 0; } else if(htd == 3 && hunremove == 1) { if(htx > 0 && hgrid[htx-1][hty] != 1) htx = htx - 1; else if(hty > 0 && hgrid[htx][hty-1] != 1) { hty = hty - 1; htd = 2; } else hunremove = 0; } } if(success == 1) printf("%d %d\n", ansx, ansy); else printf("-1\n"); } return 0; }
相关文章推荐
- hdu 4741 2013杭州赛区网络赛 dfs ***
- hdu 4412 2012杭州赛区网络赛 期望
- hdu 4739 2013杭州赛区网络赛 寻找平行坐标轴的四边形 **
- HDU 4578 Transformation(2013 杭州赛区全国邀请赛 1003)
- Caocao's Bridges hdu4738 (网络赛 杭州赛区) hdu 4738
- HDU 4417 Super Mario 第37届ACM/ICPC 杭州赛区网络赛1008题(树状数组或者线段树)
- hdu 4738 2013杭州赛区网络赛 桥+重边+连通判断 ***
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
- HDU - 6208 The Dominator of Strings (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1003)
- HDU 4778 Gems Fight! (2013杭州赛区1009题,状态压缩,博弈)
- hdu 5889 Barricade 2016ACM/ICPC青岛赛区网络赛1011
- HDU 4460 Friend Chains(2012年杭州赛区现场赛H题)
- HDU 5884 Sort -2016 ICPC 青岛赛区网络赛
- hdu 4278 2012天津赛区网络赛 数学 *
- HDU - 6198 number number number (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1005)
- Hdu 4292 Food (2012成都赛区网络赛第五题,拆点网络流)
- 2015 ACM ICPC 长春赛区 网络赛 HDU 5437 Alisha’s Party
- HDU 4998 Rotate(计算几何)2014年鞍山赛区网络赛
- hdu 4741 Save Labman No.004 [2013年杭州ACM网络赛]
- HDU 4770 Lights Against Dudely -- 2013 杭州赛区现场赛-A(状态压缩)