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 | 29 | 30 |
Tags
- 투 포인터
- 백준
- 트리
- BFS
- 정렬
- 그래프
- ue5
- 유니티
- 수학
- 자료구조
- XR Interaction Toolkit
- 시뮬레이션
- 유니온 파인드
- VR
- 문자열
- 재귀
- DFS
- c++
- 누적 합
- 브루트포스
- Unreal Engine 5
- 우선순위 큐
- 알고리즘
- 그리디 알고리즘
- Team Fortress 2
- 백트래킹
- 다이나믹 프로그래밍
- 스택
- 다익스트라
- 구현
Archives
- Today
- Total
1일1알
백준 2448번 별 찍기 - 11 C++ 본문


삼각형의 높이, row, col 정보를 이용하여 재귀를 통해 문제를 해결하였다.
#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 <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
void rec(int height, int row, int col, vector<vector<char>> &board) {
if (height == 3) {
board[row][col] = '*';
board[row + 1][col - 1] = '*';
board[row + 1][col + 1] = '*';
for (int i = col - 2; i <= col + 2; i++) {
board[row + 2][i] = '*';
}
return;
}
rec(height / 2, row, col, board);
rec(height / 2, row + height / 2, col - height / 2, board);
rec(height / 2, row + height / 2, col + height / 2, board);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<vector<char>> board(n, vector<char>(n * 2 - 1, ' '));
rec(n, 0, n - 1, board);
for (auto a : board) {
for (auto b : a) {
cout << b;
}
cout << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 2096번 내려가기 C++ (0) | 2022.03.31 |
---|---|
백준 9935번 문자열 폭발 C++ (0) | 2022.03.28 |
백준 4963번 섬의 개수 C++ (0) | 2022.03.26 |
백준 1120번 문자열 C++ (0) | 2022.03.24 |
백준 1475번 방 번호 C++ (0) | 2022.03.23 |