Skip to content

[4주차] 고다혜 #48

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

[4주차] 고다혜 #48

merged 11 commits into from
Oct 6, 2024

Conversation

KodaHye
Copy link
Contributor

@KodaHye KodaHye commented Sep 30, 2024

No description provided.

static int[][] map;
static boolean[][] v;
static int[] dr = {1, 0, -1, 0}, dc = {0, 1, 0, -1};
static ArrayDeque<Point> q, tmp;
Copy link
Contributor

Choose a reason for hiding this comment

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

Deque 사용해서 푸셨군요,,!!👍 👍Stack이랑 Queue가 더 익숙하다는 이유로 Deque사용을 계속 미루고 있는데,, 위치랑 값을 함께 관리할 수 있어서 훨씬 효율적인 것 같아요! 저도 Deque 공부하고 꼭 Deque으로 풀어보겠습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

구현 인터페이스가 다르고, Deque에 있는 함수가 좀 더 많을 뿐, QueueDeque랑 거의 비슷해서 바로 써보셔도 좋을 것 같습니당!!!

}
}

while(!tmp.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

오호 큐로 관리하면 바로 계란을 업데이트할 수 있어서 좋네요!

return flag;
}

static boolean isInRange(int a, int b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

계란 이동 범위도 함수로 빼서 짱 깔끔하네요!!👍

}

static boolean isInRange(int a, int b) {
return Math.abs(a - b) >= L && Math.abs(a - b) <= R;
Copy link
Contributor

Choose a reason for hiding this comment

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

Math.abs(a - b) 같은 결과값이 두번 작성되어서 변수로 따로 받아서 1번만 작성하는게 좋을 것 같습니다 ㅎㅎ

Suggested change
return Math.abs(a - b) >= L && Math.abs(a - b) <= R;
int abs = Math.abs(a - b);
return abs >= L && abs <= R;


// 입력받은 별의 위치에 대해 모든 경우의 수를 pq에 넣어줌
static void setQ() {
for(int i = 0; i < points.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

영향은 없겠지만 조건문이 i < points.length - 1이 되야할 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗 넵!! 살짝 고민하다가,,, ㅋㅎㅋㅎ 한 번 연산 차이고, 귀찮아서,,,, 넘어갔는데,,, 짚어주셔서 감사합니다!!

Comment on lines 53 to 60
// rank가 작은 것을 큰 쪽으로 붙이기
if(rank[a] < rank[b]) p[a] = b;
else if(rank[a] > rank[b]) p[b] = a;
// rank가 같다면, 한 쪽 rank 늘려주고 거기에 붙이기
else {
rank[a]++;
p[a] = b;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

랭크를 이용한 Union연산 최적화 기억해주셔서 감사함다..😹

Copy link
Contributor Author

Choose a reason for hiding this comment

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

처음엔 사용안하고, 두 번째 풀이에서 생각나서 사용해봤습니다!
헐 근데 다시 보니까 이상할걸 찾았는데, p[a] = b가 아니라 p[b] = a가 되어야하네요 ??,,,,,!!ㅋ ㅋㅎㅋㅎㅋㅎㅋㅎ 수정하겠습니다

Copy link
Contributor

Choose a reason for hiding this comment

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

저도 다음번에 rank 연산 사용해봐야겠습니다~

int current = i == N ? L: arr[i];
int prev = i == 0 ? 0: arr[i - 1];

cnt += ((current - prev - 1) / dis);
Copy link
Contributor

Choose a reason for hiding this comment

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

우와아아 휴게소 갯수 구하는 함수 짱 간결하고 깔끔하네요!!!!
전 거리 배열 따로 만들고, %==0으로 이미 있는 휴게소인지 판단했는데 거리 값 구할때 -1해주면 깔끔하게 처리가 되군요!!👍👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

시작점과 끝점, 그리고 이미 설치된 곳은 설치를 못하니 currentprev가 배열 idx를 넘어가는 경우만 처리해주면 저렇게 나타낼 수 있겠더라구요!!

수빈님 하신 것도 구경가보겠습니당!!!

@KodaHye KodaHye changed the title [3주차] 고다혜 [4주차] 고다혜 Oct 2, 2024
}

public int solution(int m, int n, int[][] puddles) {
existPuddle = new boolean[n][m];
Copy link
Contributor

@Jewan1120 Jewan1120 Oct 3, 2024

Choose a reason for hiding this comment

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

이 배열과 dp배열의 크기를 1씩 늘려주고 첫 시작을(1,1)로 하면 계산하기 편할 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

그러면 check 함수도 안써도 돼서 좋을 것 같네요 !! 👍


class DH_42898 {
static final int MOD = 1_000_000_007;
static int[] dr = {0, -1}, dc = {-1, 0};
Copy link
Contributor

Choose a reason for hiding this comment

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

오른쪽과 아래로만 이동하는 조건을 잘 활용하셨네요! 저도 처음 접근할 때 좌표 계산을 고려하다가 아직 어려워서 다른 방법으로 풀었는데, 배워갑니다! 👍

public int solution(int[] people, int limit) {
int answer = 0;

Deque<Integer> q = new ArrayDeque<>();
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.

근데 2개의 포인터를 둬서 풀이하는 것과 잠깐 고민했는데, 메모리, 시간 효율성보다는 빠르게 풀릴 것 같은 풀이를 선택하는 습관을 버려야될 것 같습니다 ㅜㅜ !!!

while (!q.isEmpty()) {
// pollLast를 하며 숫자가 큰 것부터 처리
int current = q.pollLast();
// 제한을 넘는다면 continue
Copy link
Contributor

Choose a reason for hiding this comment

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

전 범위같이 자잘한 예외처리 잘 놓치는데, 항상 예외처리 잘해주시는것 같아요!👍
(이번 문제에선 limit가 항상 최대몸무게보다 크게 주어진다고 나와있네요!)

Copy link
Contributor Author

@KodaHye KodaHye Oct 4, 2024

Choose a reason for hiding this comment

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

오 필요 없는 코드였네요 ㅎㅎ !!! 알려주셔서 감사합니다 !!

문제 잘 읽는 습관 들여야겠어요 ㅎㅎ...

@baexxbin baexxbin merged commit 0f3ec41 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