Skip to content

[4주차] 백제완 #49

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 9 commits into from
Oct 6, 2024
Merged

[4주차] 백제완 #49

merged 9 commits into from
Oct 6, 2024

Conversation

Jewan1120
Copy link
Contributor

No description provided.

// 별과 별 사이의 거리 계산
private static double calDistance(double[] A, double[] B) {
return Math.abs(Math.sqrt(Math.pow(B[0] - A[0], 2) + Math.pow(B[1] - A[1], 2)));
}
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

@Jewan1120 Jewan1120 Oct 1, 2024

Choose a reason for hiding this comment

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

그러게여..🐹 필요없는 연산입니다!
수정했습니다 ㅎ 감사합니다

System.out.println(left);
}

// 해당 값으로 주유소를 지었을 때 m개 이하로 지을 수 있는지
Copy link
Contributor

Choose a reason for hiding this comment

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

오호.. 다들 휴게소 개수 짱 깔끔하게 구하셨군요..!!👍

System.out.println(n - len);
}

// 빠른 입력 함수
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.

나중에 같이 입력함수 이야기해봐요!

int[][] board = new int[n + 1][m + 1];
// 웅덩이가 있는 위치 표시
for (int[] puddle : puddles)
board[puddle[1]][puddle[0]] = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 웅덩이가 있는 곳을 2차원 boolean 배열을 만들어서 저장해줬는데, 그냥 int형 배열에 모두 다 저장해줘도 됐군요,,,,👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

최대한 하나의 배열에서 끝내려고 -1로 표기했더니 계산도 간단해지고 괜찮더라구요!

// 현재 위치가 웅덩이가 아니라면
if (board[i][j] != -1) {
int up = Math.max(0, board[i - 1][j]); // 위쪽에서 오는 경우
int lf = Math.max(0, board[i][j - 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.

최댓값으로 0과 함께 받아오면 체크해둔 -1을 무시할 수 있어요!

l++;
}
r--;
answer++;
Copy link
Contributor

Choose a reason for hiding this comment

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

따로 else문 필요 없이 한번에 증가도 가능하군요...!!
저는 2명 타는 경우랑 1명 타는 경우 이렇게 나눠서 생각 하다보니 else문으로 나눠줬었는데, 불필요한 구현 없이 깔끔한 코드 배워갑니다!👍

@baexxbin baexxbin merged commit aea2f2c into GreatAlgorithm-Study:main Oct 6, 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.

6 participants