Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

허준혁 / 11월 2주차 / 월, 목 #325

Merged
merged 8 commits into from
Nov 11, 2023
Merged
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
78 changes: 78 additions & 0 deletions HuhJunHyeok/boj/boj11037.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
* [boj] 11037. 중복 없는 수
*/
public class boj11037 {
static ArrayList<Integer> noOverlapNumList = new ArrayList<>();
static int num, answerIdx;
static int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
static boolean[] visited = new boolean[9];
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

for(int i = 1; i <= 9; i++) {
makeNoOverlapNum(0, 0, i);
}
// System.out.println(noOverlapNumList.toString());

String strNum = "";
while((strNum = br.readLine()) != null && (!strNum.isEmpty())) {
// System.out.println("strNum" + strNum);
num = Integer.parseInt(strNum);
// System.out.println(num);
if(num >= 987654321) {
sb.append(0).append("\n");
} else {
upperBound();
sb.append(noOverlapNumList.get(answerIdx)).append("\n");
// System.out.println(noOverlapNumList.get(answerIdx));
}
}

System.out.print(sb.toString());
}

/**
* 순열을 이용하여 중복 없는 수를 모두 구함
* @param nowLength
* @param nowNum
* @param minLength
*/
public static void makeNoOverlapNum(int nowLength, int nowNum, int minLength) {
if(nowLength >= minLength) {
noOverlapNumList.add(nowNum);
} else {
for(int i = 0; i < 9; i++) {
if(!visited[i]) {
visited[i] = true;
makeNoOverlapNum(nowLength + 1, nowNum * 10 + numbers[i], minLength);
visited[i] = false;
}
}
}
}

/**
* upperbound를 사용하는 bianry search로 탐색.
*/
public static void upperBound() {
int low = 0;
int high = noOverlapNumList.size();

while(low <= high) {
int mid = (low + high) >> 1;

if(noOverlapNumList.get(mid) <= num) {
low = mid + 1;
} else {
answerIdx = mid;
high = mid - 1;
}
}
}
}
75 changes: 75 additions & 0 deletions HuhJunHyeok/boj/boj14226.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

/**
* [boj] 14226. 이모티콘
*/
public class boj14226 {
static class Status {
int screenEmoticonCnt;
int clipboardEmoticonCnt;
int time;

public Status(int screenEmoticonCnt, int clipboardEmoticonCnt, int time) {
this.screenEmoticonCnt = screenEmoticonCnt;
this.clipboardEmoticonCnt = clipboardEmoticonCnt;
this.time = time;
}
}
/**
* S: 최종 이모티콘의 수
*/
static int S, maxSize;
static boolean[][] visited;
static Queue<Status> statusQueue = new ArrayDeque<>();

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

S = Integer.parseInt(br.readLine());
maxSize = S << 1;

System.out.println(bfs());
}

public static int bfs() {
visited = new boolean[maxSize + 1][maxSize + 1];
visited[1][0] = true;

statusQueue.offer(new Status(1, 0, 0));

while(!statusQueue.isEmpty()) {
Status now = statusQueue.poll();

if(now.screenEmoticonCnt == S) {
return now.time;
}

if(now.screenEmoticonCnt > 0 && now.screenEmoticonCnt < maxSize) {
// 화면에 있는 이모티콘을 모두 복사해서 클립보드에 저장
if(!visited[now.screenEmoticonCnt][now.screenEmoticonCnt]) {
visited[now.screenEmoticonCnt][now.screenEmoticonCnt] = true;

statusQueue.offer(new Status(now.screenEmoticonCnt, now.screenEmoticonCnt, now.time + 1));
}

// 화면에 있는 이모티콘 중 하나를 삭제
if(!visited[now.screenEmoticonCnt - 1][now.clipboardEmoticonCnt]) {
visited[now.screenEmoticonCnt - 1][now.clipboardEmoticonCnt] = true;

statusQueue.offer(new Status(now.screenEmoticonCnt - 1, now.clipboardEmoticonCnt, now.time + 1));
}
}

// 클립보드에 있는 모든 이모티콘을 화면에 붙여넣기
if(now.clipboardEmoticonCnt > 0 && now.screenEmoticonCnt + now.clipboardEmoticonCnt < maxSize) {
visited[now.screenEmoticonCnt + now.clipboardEmoticonCnt][now.clipboardEmoticonCnt] = true;

statusQueue.offer(new Status(now.screenEmoticonCnt + now.clipboardEmoticonCnt, now.clipboardEmoticonCnt, now.time + 1));
}
}
return -1;
}
}
71 changes: 71 additions & 0 deletions HuhJunHyeok/boj/boj14711.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
* [boj] 14711. 타일 뒤집기 (Easy)
*/
public class boj14711 {
/**
* N: 게임판의 크기
*/
static int N;
/**
* board: 게임판
*/
static char[][] board;
static boolean[][] visited;
/**
* dr, dc: delta값. 하좌우 순서.
*/
static int[] dr = {1, 0, 0}, dc = {0, -1, 1};
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

N = Integer.parseInt(br.readLine());

board = new char[N][N];
visited = new boolean[N][N];
String firstLine = br.readLine();
for(int i = 0; i < N; i++) {
board[0][i] = firstLine.charAt(i);
sb.append(board[0][i]);
}
sb.append("\n");

solve();

System.out.print(sb.toString());

}

public static void solve() {
for(int i = 0, checkSize = N - 1; i < checkSize; i++) {
for(int j = 0; j < N; j++) {
if(board[i][j] == '#') {
for(int d = 0; d < 3; d++) {
int nextR = i + dr[d];
int nextC = j + dc[d];

if(!isInBoard(nextR, nextC)) {
continue;
}

visited[nextR][nextC] = !visited[nextR][nextC];
}
}
}

for(int j = 0; j < N; j++) {
board[i + 1][j] = visited[i][j] ? '#' : '.';
sb.append(board[i + 1][j]);
}
sb.append("\n");
}
}

public static boolean isInBoard(int r, int c) {
return 0 <= r && r < N && 0 <= c && c < N;
}
}
Loading
Loading