程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> hdu 5652 India and China Origins

hdu 5652 India and China Origins

編輯:關於C++

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 integerTwhich represents the number of test cases.

For each test case, the first line contains two space seperated integersN,M. nextNlines consists of strings composed of0,1characters.1denoting that there's already a mountain at that place,0denoting the plateau. onN+2line there will be an integerQdenoting the number of mountains that rised up in the order of times. NextQlines contain2space seperated integersX,Ydenoting that at ith year a mountain rised up at locationX,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
   
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved