※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 3234번 문제인 LUKA이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/3234
3234번: LUKA
The first line of the input file consists of two inegers X and Y, -10000 ≤ X,Y ≤ 10000, Luka's position. In the next line is an integer K, 1 ≤ K ≤ 100,000. The following line holds K charachters that show us the route that The Task Makers were taki
www.acmicpc.net
문자를 하나씩 읽어나가면서 task makers의 위치를 매 시각 구해내고, 매 시각 Luka와 task makers가 인접해있는지를 확인해 문제를 해결하자.
두 좌표가 인접해있는지 여부는 아래 구현에서의 dx 와 dy 배열을 이용해 간단한 구현으로 알아볼 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int X, Y, x, y;
int K;
bool printed;
int dx[9] = { 0,1,1,1,0,-1,-1,-1,0 };
int dy[9] = { 0,1,0,-1,-1,-1,0,1,1 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> X >> Y >> K;
for (int i = 0; i < 9; i++) {
if (x + dx[i] == X && y + dy[i] == Y) {
cout << 0 << '\n';
printed = 1;
}
}
for (int k = 1; k <= K; k++) {
char c; cin >> c;
if (c == 'I') x++;
else if (c == 'S') y++;
else if (c == 'Z') x--;
else y--;
for (int i = 0; i < 9; i++) {
if (x + dx[i] == X && y + dy[i] == Y) {
cout << k << '\n';
printed = 1;
}
}
}
if (!printed) cout << -1;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 15831 // C++] 준표의 조약돌 (0) | 2023.08.18 |
---|---|
[BOJ 6904 // C++] Picture Perfect (0) | 2023.08.17 |
[BOJ 6905 // C++] Snakes and Ladders (0) | 2023.08.17 |
[BOJ 17613 // C++] 점프 (0) | 2023.08.17 |
[BOJ 2729 // C++] 이진수 덧셈 (0) | 2023.08.16 |