슈뢰딩거의 고등어

[프로그래머스] 행렬 테두리 회전하기 본문

알고리즘

[프로그래머스] 행렬 테두리 회전하기

슈뢰딩거의 고등어 2022. 2. 8. 10:47

https://programmers.co.kr/learn/courses/30/lessons/77485

 

코딩테스트 연습 - 행렬 테두리 회전하기

6 6 [[2,2,5,4],[3,3,6,6],[5,1,6,3]] [8, 10, 25] 3 3 [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]] [1, 1, 5, 3]

programmers.co.kr

 

점이 주어지는 경우 2가지

이동가능 경로 상하좌우 4가지

한번만 도는게 아니기때문에 실제 이동을 해야함.

  1. 각 블록을 이동을 시킨다.
  2. 이동하는 값들을 vector 에 저장한다.
  3. vector 에 있는 값중 min 을 구한다

이동함수 구상...

  1. ax = min(x1, x2)
  2. bx = max(x1, x2)
  3. ay = min(y1, y2)
  4. by = max(y1, y2)

if (by == y && ax≥ x && x < bx) : →

else if (ay == y && ax> x && x ≥ bx) : ←

else if (ax== x && ay≥ y && y < by) : 상

else if (ay == y && ay> y && y ≥ by) : 하

#include <string>
#include <vector>

using namespace std;

int arr[110][110];
int ax, ay, bx, by;

void define_abxy(vector<int> query) {
    ax = min(query[0], query[2]);
    bx = max(query[0], query[2]);
    ay = min(query[1], query[3]);
    by = max(query[1], query[3]);
}

void create_arr(int colums) {
    int i=1;
    for(int i=1; i<=columns; i++) {
        for(int j=1; j<=colums; j++) {
            arr[i][j] = i++;
        }
    }
}

int move_block(vector <int> query) {
    if (by == y && ax≥ x && x < bx) : →

    else if (ay == y && ax> x && x ≥ bx) : ←

    else if (ax== x && ay≥ y && y < by) : 상

    else if (ay == y && ay> y && y ≥ by) : 하
}

vector<int> solution(int rows, int columns, vector<vector<int>> queries) {
    vector<int> answer;
    create_arr(columns);
    
    int i=0;
    while(rows--) {
        define_abxy(queries[i]);
        answer.push_back(move_block(queries[i++]));
    }
    return answer;
}
Comments