India and China Origins
Time Limit: 2000/2000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 901Accepted Submission(s): 309
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
Twhich represents the number of test cases.
For each test case, the first line contains two space seperated integers
N,M. next
Nlines consists of strings composed of
0,1characters.
1denoting that there's already a mountain at that place,
0denoting the plateau. on
N+2line there will be an integer
Qdenoting the number of mountains that rised up in the order of times. Next
Qlines contain
2space seperated integers
X,Ydenoting 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
0≤Y
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
題意 一開始有一個地圖 白格能走 黑格不能走 只能走到相鄰格子 起點是最上面一層隨意的白格 終點是底層的白格
之後的Q年中 每年都會在Xq,Yq的格子中出現一座山 該格子將不能通行 問第幾年時 沒有路徑從上走到下
一道簡單的搜索題,先記錄一天從上到下的路徑,若生成的山在記錄的路徑上,就重新搜索路徑,知道沒有路徑或者沒有山生成。不必要每次生成山就去搜索一次路徑
#include
#include
#include
#include
#include
using namespace std;
int n,m;
char Map[505][505];
bool vis[505][505]; //記錄一條從上走到下的路徑 經過的點是true
int dir[4][2]= {0,1,1,0,0,-1,-1,0};
int rr;
struct node
{
int x,y;
bool cheak()
{
if(x>=0&&x=0&&yq;
int mat[505][505];
memset(mat,-1,sizeof(mat));
memset(vis,false ,sizeof(vis));
node st,ed;
for(int i=0; i