-
Notifications
You must be signed in to change notification settings - Fork 4
[4주차] 배수빈 #46
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
Conversation
private static int bfs(int x, int y, int idx){ | ||
Queue<Node> que = new ArrayDeque<>(); | ||
que.offer(new Node(x, y)); | ||
visited[x][y] = idx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방문배열에 idx를 저장해서 문제를 풀이하셨군요!!! 저는 임시 큐를 만들어서 좌표의 위치를 저장했는데, 좋은 방법인 것 같습니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
임시 큐로 만드는 방법도 구경하고 왔는데, 바로 업데이트할 수 있어서 좋은 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
값 재할당 하는 부분에 다들 개성있으셔서 재밌어요🤓
if(visited[i][j]==0){ | ||
int tmp = bfs(i, j, idx); | ||
split[idx] = tmp; | ||
if(tmp==board[i][j]) flag++; // 나눈 결과==원래자신, 계란이동X |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
계란이동X 조건을 나눈 결과 == 원래 자신으로 설정할 수도 있군요!! 배워갑니다👍
private static int bfs(int x, int y, int idx){ | ||
Queue<Node> que = new ArrayDeque<>(); | ||
que.offer(new Node(x, y)); | ||
visited[x][y] = idx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
값 재할당 하는 부분에 다들 개성있으셔서 재밌어요🤓
for(int i=0; i<N; i++){ | ||
for(int j=0; j<N; j++){ | ||
board[i][j] = split[visited[i][j]]; // 새로운 값은, split[idx]에 해당하는 값(visited에 idx값 가지고 있음) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1차원 배열을 이용해서 누적합으로 계산하고 인덱스로 가져오는 방법이 새롭네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정말 1차원 배열로 풀이하니깐 비용도 적게들고 좋은 방법인 것 같습니다! 배워갑니당 👍
int[] dp = new int[N + 1]; | ||
int mx = 0; | ||
for (int x : child) { // 연속되는 부분증가 수열 찾기 | ||
dp[x] = dp[x-1]+1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 이 부분을 dp[num] = dp[num - 1] != 0 ? dp[num - 1] + 1 : 1;
이렇게 했는데, 괜한 연산을 했군요 ,,,,,,,,,,!!!!!!!!!!!!!!!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수빈님 코드 보고 제 코드 수정했습니다 ㅎㅎㅎ!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잌ㅎㅋㅎㅋㅎ좋습니다!!😁
dp[i][j] = 0; | ||
continue; | ||
} | ||
dp[i][j] += (dp[i-1][j]+dp[i][j-1])%MOD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 점화식 진짜 깔끔하시네요...!
저는 위쪽에서 오는 경우의 수, 아래에서 오는 경우의 수 나눠서 풀었는데 그냥 바로 이렇게 해도되는군요👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 최종적으론 위에서 오는 경우랑 오른쪽에서 오는 경우를 합해야하기에 같이 더해줬습니다!👍
for (int d : betweenDist) { | ||
if (d%x==0) cnt+= d / x > 0 ? d / x - 1 : 0; | ||
else cnt += d/x; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (d%x==0) cnt+= d / x > 0 ? d / x - 1 : 0;
나누어 떨어지면... 이후의 연산과정을 설명해주실 수 있을까요😭?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 우선, 예진님이 d%x=0
했을때 -1해준거랑 같은 원리입니다!
그런데 제 기억엔, 나누기하는 과정에서 음수값이 나오는 경우도 있어서 삼항연산자
로 처리해주었습니다.
(조건) ? (참일때 값) : (거짓일때 값)
- 조건: d/x가 0보다 크다면
- 참일 경우: d/x-1값 사용
- 거짓일 경우: 0 사용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하? 그렇군요! 감사합니다
Co-authored-by: 이예진 <86579541+yeahdy@users.noreply.github.com>
No description provided.