如何运用C语言程序编写的技术来实现这个方块移动的问题的

Problem Description
A long time ago there are no himalayas between India and China, the both cultures are frequently exchanged and are kept in sync at that time, but eventually himalayas rise up. With that at first the communation started to reduce and eventually died.

Let's assume from my crude drawing that the only way to reaching from India to China or viceversa is through that grid, blue portion is the ocean and people haven't yet invented the ship. and the yellow portion is desert and has ghosts roaming around so people can't travel that way. and the black portions are the location which have mountains and white portions are plateau which are suitable for travelling. moutains are very big to get to the top, height of these mountains is infinite. So if there is mountain between two white portions you can't travel by climbing the mountain.
And at each step people can go to 4 adjacent positions.

Our archeologists have taken sample of each mountain and estimated at which point they rise up at that place. So given the times at which each mountains rised up you have to tell at which time the communication between India and China got completely cut off.

Input
There are multi test cases. the first line is a sinle integer T which represents the number of test cases.

For each test case, the first line contains two space seperated integers N,M. next N lines consists of strings composed of 0,1 characters. 1 denoting that there's already a mountain at that place, 0 denoting the plateau. on N+2 line there will be an integer Q denoting the number of mountains that rised up in the order of times. Next Q lines contain 2 space seperated integers X,Y denoting that at ith year a mountain rised up at location X,Y.

T≤10

1≤N≤500

1≤M≤500

1≤Q≤N∗M

0≤X<N

0≤Y<M

Output
Single line at which year the communication got cut off.

print -1 if these two countries still connected in the end.

Hint:

From the picture above, we can see that China and India have no communication since 4th year.

Sample Input
1
4 6
011010
000010
100001
001000
7
0 3
1 5
1 3
0 0
1 2
2 4
2 1

Sample Output
4

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

0
方块在网格里的排列的算法问题,这个问题的C语言编程的解答的方式
1
俄罗斯方块是否能在矩形中填充的一个算法问题,怎么用C语言编程解决的
0
计算这个棋盘一共有多少条路经,采用C程序的射击的语言的方式来实现
0
方块网格的排列的顺序的问题,怎么利用C语言的程序的设计的方式来实现的
1
方块染色算法的计算机的求解过程,怎么利用C程序语言的设计的技术来编写代码的
0
俄罗斯方块是否能够填充的判断的一个算法,怎么采用C语言的程序编程的过程来实现的呢?
0
用字符构成的立体方块图的算法,怎么采用C程序的代码语言的编写的过程实现?
0
俄罗斯方块中方块的覆盖率的计算的问题,怎么才能运用C语言的程序的代码编写的思想去实现的呢?
0
计算网格中是否可以用指定的方块填充,怎么使用C语言的程序编写思想的方式实现
0
不同的黑白方块的摆放问题,具体解决怎么采用C语言的程序编写的过程去实现呢?
0
俄罗斯方块堆放在网格里的做法,怎么使用C语言的程序编写的代码的思想来解决此算法
0
计算正多面体形的表面的方块的编号问题,怎么采用C语言的程序设计的办法来实现的
0
俄罗斯方块在矩阵列中的排列的问题,如何运用 C 语言的程序代码编写的思想的方法来实现这个排列
0
方块解锁游戏用程序编写来实现,怎么用C语言的程序的代码编写的方式具体的实现的思想是怎么样的
2
怎样写一个单击鼠标进入一个模块,C语言。
0
有多少种方法来填充方块图的剩下的部分,采用C语言的程序的代码的计算的方法来解决
0
Caves方块的计算搜索,用C语言程序实现的过程
0
圆圈和方块的排列问题,用 C 语言
1
Android平移动画怎么实现这个效果?
1
区域统计问题,求大佬指点?