Skip to content
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
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10)

# 1. 프로젝트 이름 설정 (원하는 이름으로 변경 가능)
project(MyProject)

# 2. C++ 표준 설정 (C++11, 14, 17, 20 중 선택)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 3. 실행 파일 생성
# add_executable(실행파일명 소스파일.cpp)
# 예: main.cpp를 컴파일하여 my_program이라는 실행 파일을 만듦
add_executable(my_program /weekly/week02/BOJ_1965_상자넣기/Hexeong.cpp)
38 changes: 38 additions & 0 deletions weekly/week10/BOJ_12919_A와B2/Hexeong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
// AI의 피드백 : SB를 1개로 유지하고 process가 끝난 이후 원상태로 복구하는 방식으로 최적화하자.
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String S = br.readLine();
String T = br.readLine();

StringBuilder sb = new StringBuilder(T);

System.out.println(process(sb, S) ? 1 : 0);
}

private static boolean process(StringBuilder sb, String S) {
if (sb.toString().equals(S)) {
return true;
}
if (sb.length() <= S.length()) {
return false;
}

if (sb.charAt(sb.length() - 1) == 'A' && process(removeAtoSb(sb), S)) {
return true;
}
return sb.charAt(0) == 'B' && process(reverseAndDeleteBtoSb(sb), S);
};

private static StringBuilder removeAtoSb(StringBuilder sb) {
return new StringBuilder(sb).deleteCharAt((sb.length() - 1));
}

private static StringBuilder reverseAndDeleteBtoSb(StringBuilder sb) {
return new StringBuilder(sb).reverse().deleteCharAt((sb.length() - 1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.hexeong.baekjoon;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
// AI의 피드백 : Wrapper 클래스 사용을 지양하자.
// 또한, 코테에서는 클래스의 멤버 메서드 사용하지 말고 배열을 직접 조작하는 방식을 사용하자.
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());

Section[] belt = new Section[2 * N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < 2 * N; i++) {
belt[i] = new Section(false, Integer.parseInt(st.nextToken()));
}

int round = 0;
int cntZeroSection = 0;
int startIdx = 0;
while (cntZeroSection < K) {
round++;

// 1. 로봇과 함께 회전
startIdx = (startIdx - 1 + 2 * N) % (2 * N);
int loweridx = (startIdx + N - 1) % (2 * N);
belt[loweridx].setRobotExists(false);

// 2. N-2부터 0까지 앞으로 1칸 이동
int targetIdx = (startIdx + N - 2) % (2 * N);
int endIdx = startIdx - 1 < 0 ? 2 * N - 1 : startIdx - 1;
for (int curIdx = targetIdx; curIdx != endIdx; curIdx = (curIdx == 0 ? 2 * N - 1 : curIdx - 1)) {
int nextIdx = (curIdx + 1) % (2 * N);
if (belt[curIdx].getRobotExists()
&& !belt[nextIdx].getRobotExists()
&& belt[nextIdx].getDurability() > 0) {

belt[nextIdx].setRobotExists(true);
belt[nextIdx].setDurability(belt[nextIdx].getDurability() - 1);
belt[curIdx].setRobotExists(false);

// 2-1. 내구도가 0이 됐으면 cntZeroSection += 1;
if (belt[nextIdx].getDurability() == 0)
cntZeroSection++;

if (nextIdx == loweridx) { // N-1 위치에 로봇이 오면 즉시 내린다.
belt[nextIdx].setRobotExists(false);
}
}
}

// 3. 올리는 위치에 있는 칸의 내구도가 0이 아니라면 올리는 위치에 로봇을 올리기
if (belt[startIdx].getDurability() > 0) {
belt[startIdx].setRobotExists(true);
belt[startIdx].setDurability(belt[startIdx].getDurability() - 1);
// 3-1. 내구도가 0이 됐으면 cntZeroSection += 1;
if (belt[startIdx].getDurability() == 0)
cntZeroSection++;
}
}

System.out.println(round);
}

static class Section {
private Boolean isRobotExists;
private Integer durability;
public Section(boolean isRobotExists, Integer durability) {
this.isRobotExists = isRobotExists;
this.durability = durability;
}

public Boolean getRobotExists() {
return isRobotExists;
}

public Integer getDurability() {
return durability;
}

public void setRobotExists(Boolean robotExists) {
isRobotExists = robotExists;
}

public void setDurability(Integer durability) {
this.durability = durability;
}
}
}
Loading