본문 바로가기

Algorithm24

[Baekjoon][14500] 테트로미노 출처 - 백준사이트 14500번: 테트로미노 나의 풀이 'ㅗ' 모양의 블럭을 제외하고 나머지 블록은 시작점에서 부터 3칸을 임의로 이동하는 경우이다. 따라서, 완전 탐색으로 이미 왔던 칸은 가지않도록하고 3칸을 이동한 후에 최대값을 구하면 된다. 'ㅗ' 모양은 따로 예외처리하여 구한다. #include #define MAX_SIZE 500 using namespace std; const int dy[] = {-1, 1, 0, 0}; const int dx[] = {0, 0, -1, 1}; int N, M; int map[MAX_SIZE][MAX_SIZE]; bool visit[MAX_SIZE][MAX_SIZE]; int result = 0; void tetromino(int .. 2022. 2. 16.
[Baekjoon][14499] 주사위 굴리기 출처 - 백준사이트 14499번: 주사위 굴리기 나의 풀이 이번 문제는 난이도가 높지는 않다. 주사위를 동서남북으로 움직일때의 규칙은 방향이 같다면 동일하기 때문에, 해당 규칙을 찾아서 주사위를 이동시킨 후 조건을 따지면 된다. #include #define MAX 20 const int dy[4] = {0, 0, -1, 1}; const int dx[4] = {1, -1, 0, 0}; int N, M, K; int x, y; int map[MAX][MAX]; int dice[6] = {0, }; int Moving(int direction) { int temp = 0; int ny = y + dy[direction-1]; int nx = x + dx[direction-1]; if (0 2022. 2. 14.
[Baekjoon][13458] 시험 감독 출처 - 백준사이트 13458번: 시험감독 나의 풀이 여기서 중요한 점은 최종 결과를 담을 변수의 크기인데, B, C가 1이고 N과 응시자수 A가 최대값인 1,000,000인 경우 int의 최대값을 넘어감을 유의 한다. #include #define MAX 1000000 using namespace std; int N, B, C; int tester[MAX]; long long result; int main() { cin >> N; for (int idx = 0 ; idx > tester[idx]; cin >> B >> C; for (int idx = 0 ; idx < N ; idx++) { result++; // 총감독관은 무조건 한명이니까 더하고 if (tester[i.. 2022. 1. 17.
[Baekjoon][3190] 뱀 출처 - 백준사이트 3190번: 뱀 나의 풀이 #include #include #include #define MAX 100 // 상 우 하 좌 이동 const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; using namespace std; int N, K, L, result; int map[MAX][MAX]; // -1: 맵이 아닌곳, 0: 맵, 1: 뱀, 2: 사과 deque move_stack; deque snake; void print_map() { cout > K; for (int y = 0 ; y < N ; y++) { for (int x = 0 ; x < N ; x++) map[y][x] = 0; } for (int idx = 0 ;.. 2022. 1. 17.
[Baekjoon][12100] 2048 (Easy) 출처 - 백준사이트 12100번: 2048 (Easy) 나의 풀이 #include #include #define MAX 20 using namespace std; // 이동순서는 상 우 하 좌 const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; int N; int map[MAX][MAX] = {0, }; int result = -1; void print_map() { for (int y = 0 ; y < N ; y++) { for (int x = 0 ; x < N ; x++) { cout -1 ; y--) { if ((first_zero == -1) && (map[y][x] == 0)) // 이전에 0인 칸이 없었고, 현재가 0이면 first.. 2022. 1. 17.
[Baekjoon][13460] 구슬 탈출 2 출처 - 백준사이트 13460번: 구슬 탈출 2 해설 및 주석은 나중에 업로드 예정 #include #include #define MAX 11 using namespace std; const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; char map[MAX][MAX] = {0, }; int N, M; int result = 11; bool isOut = false, isBout = false, isRout = false; void moving(int dir) { pair Blue, Red, tBlue, tRed; bool isBstop = false, isRstop = false, isRB = false, isBR = false; isBout .. 2022. 1. 12.