Skip to content

[3주차] 고다혜 #33

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

Merged
merged 10 commits into from
Sep 28, 2024
Merged

[3주차] 고다혜 #33

merged 10 commits into from
Sep 28, 2024

Conversation

KodaHye
Copy link
Contributor

@KodaHye KodaHye commented Sep 23, 2024

No description provided.

int[] dp = new int[10_001];

dp[1] = 1; dp[2] = 2; dp[3] = 3;
for(int i = 4; i < dp.length; i++) dp[i] = dp[i - 3] + i / 2 + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

코드 짱 멋있네요....👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오롯이 제 머릿속에서 나온건 아닙니다 ㅎㅎ,,

Copy link
Contributor

Choose a reason for hiding this comment

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

이 점화식 찾으려다가 아침 다 날려먹었씀다...🐹

Copy link
Contributor

Choose a reason for hiding this comment

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

우와 한줄로 끝날 수 있군요,,??ㅎㅎㅎㅎ 점화식 세우는거 너무 어려워요 ㅜㅜㅜ

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

int[] dp = new int[10_001];
Copy link
Contributor

Choose a reason for hiding this comment

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

초기화할때 _는 무슨 의미인가요?!👀

Copy link
Contributor Author

@KodaHye KodaHye Sep 24, 2024

Choose a reason for hiding this comment

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

숫자 사이에 _를 쓸 수 있는데요, 자리수를 쉽게 파악하기 위한 용도로 사용합니다!

예를 들어 1,000,000에서 ,를 _로 나타내준거랑 같아요!

static void solution() {
int cnt = 0; // 말의 개수 세는 변수

L: while(!q.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

오오 L: 의 의미는 무엇인가요??

Copy link
Contributor Author

@KodaHye KodaHye Sep 25, 2024

Choose a reason for hiding this comment

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

이거 별로 안좋은 코드 작성법인 것 같긴 한데요,, 알고리즘 문제 풀이를 할 때, 종종 쓰긴 합니다,,!

GoTo문 느낌,,, 으로 만약 다중 반복문 안에서 특정 조건을 만족하고 탈출할 때 break문을 많이 쓰잖아요! 이 때, break 뒤에 라벨링(?)을 하는 표현식을 써주고, 해당 break문에서 나갈 for문 앞에 break 뒤에 쓴 라벨을 작성해주면, break문을 여러개 쓰지 않아도, 한 번에 라벨링해준 곳으로 나갈 수 있게 됩니다!!

아래와 같은 코드가 있을 때, 반복문을 실행하다가 if 조건이 만족하면 k에 대한 반복문을 나가는게 아니라 i반복문 앞에 라벨링이 되어 있기 때문에 전체 반복문에 대해 종료하게 됩니다!

L: for(int i = 0; i < n; i++) {
   for(int j = 0; j < n; j++) {
      for(int k = 0; k < n; k++) {
         if(k == 1) break L;
      }
   }
}

반복문이 여러개 있을 때, flag 변수를 여러 개 두면서 break를 판단하는 것보다 라벨링을 사용하는게
편할 때가 있더라구요!!,, 필요에 따라 사용하면 좋을 것 같습니다!!

근데 지금 제 코드에서는 if문을 밖으로 뺐으면 굳이 사용하지 않아도 됐었네요!!

Copy link
Contributor

Choose a reason for hiding this comment

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

우와~ 저도 맨날 flag 변수를 따로 선언해서 코드가 지저분해졌는데 완전 깔끔하게 풀 수 있는 것 같아요! 좋은 방법 배워갑니다! 감사합니당 💯

map = new int[N][N];
check = new boolean[N][N];

for(int r = N - 2; r < N; r++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

오 초기 영양제 투입도 for문으로 깔끔하게 구현했군요!

return r >= 0 && r < N && c >= 0 && c < N;
}
static void move(int d, int p) {
boolean[][] tmp = new boolean[N][N];
Copy link
Contributor

Choose a reason for hiding this comment

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

영양제 배열로 관리했다고해서 구경왔어요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ㅋㅋㅋ ㅋㅋㅋㅋ 좋습니다!!! 저도 큐를 이용해서 푸는 방식 구경했습니다 !!!!! ㅎㅎ

System.out.println(-1);
}

static void func(int depth, int idx, int cnt, boolean[][] check) {
Copy link
Contributor

Choose a reason for hiding this comment

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

재귀함수 반환 타입을 boolean으로 해서 값을 찾으면 true를 전달해서 재귀를 종료시키는 방법도 좋을 것 같아요!

@KodaHye KodaHye merged commit d0330d3 into GreatAlgorithm-Study:main Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants