Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ue5
- 백준
- 수학
- 다익스트라
- 구현
- 누적 합
- BFS
- Team Fortress 2
- 재귀
- 다이나믹 프로그래밍
- 알고리즘
- 그리디 알고리즘
- Unreal Engine 5
- VR
- 우선순위 큐
- 시뮬레이션
- DFS
- 트리
- 자료구조
- c++
- 정렬
- 브루트포스
- 유니티
- 백트래킹
- XR Interaction Toolkit
- 문자열
- 스택
- 유니온 파인드
- 그래프
- 투 포인터
Archives
- Today
- Total
1일1알
백준 13901번 로봇 C++ 본문
https://www.acmicpc.net/problem/13901
13901번: 로봇
첫 번째 줄에는 방의 크기 R, C(3 ≤ R, C ≤ 1,000)가 입력된다. 두 번째 줄에는 장애물의 개수 k(0 ≤ k ≤ 1,000)가 입력된다. 다음 k개의 줄에는 각 장애물 위치 br(0 ≤ br ≤ R – 1), bc(0 ≤ bc ≤ C - 1)가
www.acmicpc.net
실버3 문제치고는 어려운 것 같은 구현 문제
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int dRow[4] = { -1,1,0,0 };
int dCol[4] = { 0,0,-1,1 };
int r, c, k;
int dirIdx = 0;
vector<int> dirs(4);
vector<vector<int>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c >> k;
board = vector<vector<int>>(r, vector<int>(c, 0));
for (int i = 0; i < k; i++) {
int br, bc;
cin >> br >> bc;
board[br][bc] = -1;
}
int sr, sc;
cin >> sr >> sc;
board[sr][sc] = 1;
for (int i = 0; i < 4; i++) {
int dir;
cin >> dir;
dirs[i] = dir - 1;
}
while (true) {
int currDir = dirs[dirIdx];
bool canGo = false;
for (int i = 0; i < 4; i++) {
int nextIdx = (dirIdx + i) % 4;
int nextDir = dirs[nextIdx];
int nextRow = sr + dRow[nextDir];
int nextCol = sc + dCol[nextDir];
if (nextRow < 0 || nextRow >= r) continue;
if (nextCol < 0 || nextCol >= c) continue;
if (board[nextRow][nextCol] != 0) continue;
board[nextRow][nextCol] = 1;
dirIdx = nextIdx;
sr = nextRow;
sc = nextCol;
canGo = true;
break;
}
if (canGo == false) break;
}
cout << sr << " " << sc;
}
'알고리즘' 카테고리의 다른 글
백준 1735번 분수 합 C++ (0) | 2023.02.06 |
---|---|
백준 14494번 다이나믹이 뭐에요? C++ (0) | 2023.02.05 |
백준 16936번 나3곱2 C++ (0) | 2023.02.03 |
백준 13703번 물벼룩의 생존확률 C++ (0) | 2023.02.02 |
백준 11758번 CCW C++ (0) | 2023.02.01 |