devLupin / algorithm

PS
1 stars 0 forks source link

시뮬레이션 #54

Closed devLupin closed 7 months ago

devLupin commented 7 months ago
    // 시게방향으로 90도 회전
    public static int[][] rightRotate(int n, int[][] A) {
        int[][] B = new int[n][n];

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                B[i][j] = A[n-j-1][i];
            }
        }

        return B;
    }

    // 반시계 방향으로 90도 회전
    public static int[][] leftRotate(int n, int[][] A) {
        int[][] B = new int[n][n];

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                B[i][j] = A[j][n-i-1];
            }
        }

        return B;
    }

    // 위, 아래로 뒤집기
    public static int[][] reverseTopBottom(int n, int[][] A) {
        int[][] B = new int[n][n];

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                B[i][j] = A[n-i-1][j];
            }
        }

        return B;
    }

    // 좌, 우로 뒤집기
    public static int[][] reverseLeftRight(int n, int[][] A) {
        int[][] B = new int[n][n];

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                B[i][j] = A[i][n-j-1];
            }
        }

        return B;
    }
devLupin commented 7 months ago
void RotateRange(int sx, int sy, int sz) {    // 시작점, 크기
    for(int x = sx; x < sx + sz; x++) {
        for(int y = sy; y < sy + sz; y++) {

            int nx = y - sy;
            int ny = sz - (x - sx) - 1;

            next_board[nx + sx][ny + sy] = board[x][y];
        }
    }
}
devLupin commented 7 months ago
pii right(int x, int y, int d) {
    int dist=d%(2*(m-1));
    if(m-y-1<dist) {
        dist-=m-y-1;
        if(m-1<dist) {
            dist-=m-1;
            y=dist;
        }
        else y=m-1-dist;
    }
    else y+=dist;
    return {x,y};
}

pii left(int x, int y, int d) {
    int dist=d%(2*(m-1));
    if(y<dist) {
        dist-=y;
        if(m-1<dist) {
            dist-=m-1;
            y=m-1-dist;
        }
        else y=dist;
    }
    else y-=dist;
    return {x,y};
}

pii up(int x, int y, int d) {
    int dist=d%(2*(n-1));
    if(x<dist) {
        dist-=x;
        if(n-1<dist) {
            dist-=n-1;
            x=n-1-dist;
        }
        else x=dist;
    }
    else x-=dist;
    return {x,y};
}

pii down(int x, int y, int d) {
    int dist=d%(2*(n-1));
    if(n-x-1<dist) {
        dist-=n-x-1;
        if(n-1<dist) {
            dist-=n-1;
            x=dist;
        }
        else x=n-1-dist;
    }
    else x+=dist;
    return {x,y};
}
devLupin commented 7 months ago
int nx = (x + dx[d] * p + N * p) % N;
int ny = (y + dy[d] * p + N * p) % N;