Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions MINWOOK/15683-윤민욱.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Solution {

private static final int UP = 0;
private static final int RIGHT = 1;
private static final int DOWN = 2;
private static final int LEFT = 3;
private static final int WALL = 6;
private static final int MAX = 4;

public static int[][] office;
public static int n, m;
public static int min = Integer.MAX_VALUE;

public static class CCTV {

int x, y;
int type;
boolean[] directionList;

public CCTV(int x, int y, int type) {

this.x = x;
this.y = y;
this.type = type;
this.directionList = new boolean[MAX];
this.initialize();
}

public void initialize() {

if (this.type == 1) {

directionList[UP] = true;
} else if (this.type == 2) {

directionList[LEFT] = true;
directionList[RIGHT] = true;
} else if (this.type == 3) {

directionList[UP] = true;
directionList[RIGHT] = true;
} else if (this.type == 4) {

directionList[LEFT] = true;
directionList[UP] = true;
directionList[RIGHT] = true;
} else {

for (int i = 0; i < this.directionList.length; i++)
directionList[i] = true;
}
}

public void rotate() {

boolean temp = this.directionList[LEFT];
this.directionList[LEFT] = this.directionList[DOWN];
this.directionList[DOWN] = this.directionList[RIGHT];
this.directionList[RIGHT] = this.directionList[UP];
this.directionList[UP] = temp;
}

public boolean[][] inspection(boolean[][] isInspected) {

boolean[][] result = new boolean[n][m];

for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
result[i][j] = isInspected[i][j];

if (this.directionList[0]) {
for (int i = x; i >= 0; i--) {
if (office[i][y] == WALL)
break;

result[i][y] = true;
}
}
if (this.directionList[1]) {
for (int i = y; i < m; i++) {
if (office[x][i] == WALL)
break;

result[x][i] = true;
}
}
if (this.directionList[2]) {
for (int i = x; i < n; i++) {
if (office[i][y] == WALL)
break;

result[i][y] = true;
}
}
if (this.directionList[3]) {
for (int i = y; i >= 0; i--) {
if (office[x][i] == WALL)
break;

result[x][i] = true;
}
}

return result;
}
}

public static void main(String[] args) {

@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);

n = sc.nextInt();
m = sc.nextInt();

office = new int[n][m];
ArrayList<CCTV> cctvList = new ArrayList<CCTV>();
boolean[][] isInspected = new boolean[n][m];

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {

int input = sc.nextInt();
if (input == WALL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 상수 정의해서 하는거 좋음!(디버깅할때도 편함)

isInspected[i][j] = true;
}
office[i][j] = input;
if (input > 0 && input != WALL) {
cctvList.add(new CCTV(i, j, input));
}
}
}

solution(cctvList, isInspected, 0);
System.out.println(min);
}

public static void solution(ArrayList<CCTV> cctvList, boolean[][] isInspected, int index) {

if (index == cctvList.size()) {

int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!isInspected[i][j]) {
sum++;
}

}
}

if (sum < min) {
min = sum;
}
return;
}

CCTV cctv = cctvList.get(index);

for (int i = 0; i < 4; i++) {

boolean[][] temp = cctv.inspection(isInspected);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

재귀함수 안에서 배열 선언되면 깊이 못들어가는건 설명했으니까 알거고,
대안으로 이런걸 전역변수로 선언해서 재활용하는걸 공부하면 좋을듯

solution(cctvList, temp, index + 1);

cctv.rotate();
}

}

}
100 changes: 100 additions & 0 deletions MINWOOK/2583-윤민욱.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

private static final int BLOCKED = -1;
private static final int UNVISITED = 0;
private static final int VISITED = 1;

public static int m, n, k;
public static int[][] coordinate;
public static boolean[][] isVisited;
public static ArrayList<Integer> areaList;
public static int area = 0;

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner sc = new Scanner(System.in);

m = sc.nextInt();
n = sc.nextInt();
k = sc.nextInt();
coordinate = new int[m][n];
isVisited = new boolean[m][n];
areaList = new ArrayList<Integer>();

while (k > 0) {

boolean[][] isVisited = new boolean[m][n];
int i = sc.nextInt();
int j = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
dfs(j, i, y, x, isVisited);
k--;
}

int count = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {

if (coordinate[i][j] != BLOCKED && !isVisited[i][j]) {

solution(i, j);
areaList.add(area);
area = 0;
count++;
}
}
}

Collections.sort(areaList);
System.out.println(count);
for(int i : areaList)
System.out.print(i + " ");

}

public static void dfs(int i, int j, int x, int y, boolean[][] isVisited) {

coordinate[i][j] = BLOCKED;
isVisited[i][j] = true;

if (i + 1 < x && !isVisited[i + 1][j]) {

dfs(i + 1, j, x, y, isVisited);
}
if (j + 1 < y && !isVisited[i][j + 1]) {

dfs(i, j + 1, x, y, isVisited);
}
}

public static void solution(int x, int y) {

area++;
isVisited[x][y] = true;
coordinate[x][y] = VISITED;

if (x + 1 < m && coordinate[x + 1][y] != BLOCKED && !isVisited[x + 1][y]) {

solution(x + 1, y);
}
if (x - 1 >= 0 && coordinate[x - 1][y] != BLOCKED && !isVisited[x - 1][y]) {

solution(x - 1, y);
}
if (y + 1 < n && coordinate[x][y + 1] != BLOCKED && !isVisited[x][y + 1]) {

solution(x, y + 1);
}
if (y - 1 >= 0 && coordinate[x][y - 1] != BLOCKED && !isVisited[x][y - 1]) {

solution(x, y - 1);
}
}
}