#include <iostream>
using namespace std;
int check_hang(int a[100][100], int i, int j)
{
if((a[i][j-1] == 1) && (j > 0))
return -1;
if((a[i][j+1] == 1) && (j < 99))
return 1;
return 0;
}
int check_cot(int a[100][100], int i, int j)
{
if(a[i-1][j] == 1)
return 1;
return 0;
}
int main()
{
//freopen("input.txt", "r", stdin);
for(int tc = 1; tc <= 10; tc++)
{
int T, a[100][100];
int i_index = 99, j_index;
cin >> T;
for(int i = 0; i < 100; i++)
for(int j = 0; j < 100; j++)
cin >> a[i][j];
//---------------------------------------
//Tim dia chi a[i][99] = 2
for(int j = 0; j < 100; j++)
if(a[99][j] == 2)
{
j_index = j;
break;
}
//Duyet tu duoi len bat dau tu X
while(i_index > 0)
{
//check hang
if(!check_hang(a, i_index, j_index))
i_index--;
if(check_hang(a, i_index, j_index) == 1)
{
j_index++;
while(!check_cot(a, i_index, j_index))
j_index++;
i_index--;
}
if(check_hang(a, i_index, j_index) == -1)
{
j_index--;
while(!check_cot(a, i_index, j_index))
j_index--;
i_index--;
}
}
cout << "#" << tc << " " << j_index << endl;
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.