티스토리 뷰

알고리즘/SWEA

[SWEA 1210] Ladder1

히더 2018. 8. 6. 17:26

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14ABYKADACFAYh


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int result;

int arr[100][102], a, b;

bool visited[100][102];


void cal(int ii, int jj)

{

if (ii == 0)

{

result = jj - 1;

return;

}

visited[ii][jj] = true;

if (arr[ii][jj + 1] && !visited[ii][jj+1]) cal(ii, jj + 1);

else if (arr[ii][jj - 1] && !visited[ii][jj - 1]) cal(ii, jj - 1);

else if (arr[ii-1][jj] && !visited[ii-1][jj]) cal(ii-1, jj);

}


int main()

{

int T; int t;

T = 10;

while (T--)

{

cin >> t; result = 0; memset(arr, 0, sizeof(arr)); memset(visited, false, sizeof(visited));

for (int i = 0; i < 100; i++)for (int j = 1; j <= 100; j++)

{

cin >> arr[i][j];

if (arr[i][j] == 2) cal(i, j);

}

cout << "#" << t << " " << result << endl;

}


return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1213] String  (0) 2018.08.09
[SWEA 1211] Ladder2  (0) 2018.08.06
[SWEA 1209] Sum  (0) 2018.08.06
[SWEA 1204] 최빈수 구하기  (0) 2018.08.06
[SWEA 1208] Flatten  (0) 2018.08.06
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함