BOJ::문제풀이
14503 로봇 청소기
2영재
2018. 1. 28. 15:19
BOJ::14503 로봇 청소기
https://www.acmicpc.net/problem/14503
주어진 조건대로 구현하면 끝.
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <iostream> using namespace std; int n, m, r, c, d, res; int map[50][50]; int dx[] = { -1,0,1,0 }; int dy[] = { 0,1,0,-1 }; int back_dx[] = { 1,0,-1,0 }; int back_dy[] = { 0,-1,0,1 }; //0북 1동 2남 3서 void f(int x,int y,int d) { res++; map[x][y] = 2; int ax, ay; for (int i = 1; i <= 4; i++) { int dd = (d - i < 0) ? d - i + 4 : d - i; ax = x + dx[dd]; ay = y + dy[dd]; if (map[ax][ay] == 0) { f(ax, ay, dd); return; } } ax = x + back_dx[d]; ay = y + back_dy[d]; if (map[ax][ay] != 1) { f(ax, ay, d); } } int get_result() { int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (map[i][j] == 2)ans++; } } return ans; } int main() { cin >> n >> m >> r >> c >> d; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> map[i][j]; } } f(r, c, d); cout << get_result() << endl; } | cs |