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
- 유니티
- Unreal Engine 5
- 브루트포스
- 구현
- c++
- 투 포인터
- 재귀
- 백트래킹
- 그리디 알고리즘
- XR Interaction Toolkit
- 다익스트라
- Team Fortress 2
- 우선순위 큐
- BFS
- 유니온 파인드
- 다이나믹 프로그래밍
- ue5
- 그래프
- 문자열
- 알고리즘
- 누적 합
- 스택
- 자료구조
- 시뮬레이션
- 백준
- 트리
- DFS
- 정렬
- VR
- 수학
Archives
- Today
- Total
1일1알
백준 2823번 유턴 싫어 C++ 본문
https://www.acmicpc.net/problem/2823
2823번: 유턴 싫어
상근이는 여자친구와의 드라이브를 위해서 운전을 배우고 있다. 도로 연수를 10년쯤 하다 보니 운전은 그럭저럭 잘하게 되었다. 하지만, 그는 유턴을 하지 못한다. 10년동안 도로 연수를 받았지
www.acmicpc.net
처음에는 bfs문제인줄 알았는데 아니었다.
모든 길에서 인접한 길이 2개 이상이면 유턴을 하지 않고 원래 자리로 돌아올 수 있다.
#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,0,1,0 };
int dCol[4] = { 0,1,0,-1 };
int r, c;
vector<vector<char>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> c;
board = vector<vector<char>>(r, vector<char>(c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> board[i][j];
}
}
int ans = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (board[i][j] == 'X') continue;
int cnt = 0;
for (int k = 0; k < 4; k++) {
int nextRow = i + dRow[k];
int nextCol = j + dCol[k];
if (nextRow < 0 || nextRow >= r) continue;
if (nextCol < 0 || nextCol >= c) continue;
if (board[nextRow][nextCol] == 'X') continue;
cnt++;
}
if (cnt < 2) ans = 1;
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 26215번 눈 치우기 C++ (0) | 2023.01.18 |
---|---|
백준 14940번 쉬운 최단거리 C++ (0) | 2023.01.17 |
백준 20310번 타노스 C++ (0) | 2023.01.15 |
백준 17141번 연구소 2 C++ (0) | 2023.01.14 |
백준 17451번 평행 우주 C++ (0) | 2023.01.13 |