-
Notifications
You must be signed in to change notification settings - Fork 4
[3주차] 배수빈 #31
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
System.out.println(ans); | ||
} | ||
|
||
static class Node{ |
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.
사다리 상태를 객체의 메소드로 관리하니 훨씬 깔끔하고 직관적으로 확인할 수 있는 것 같아요! 👍 다음에 참고해보고 싶어요~!
while (!que.isEmpty()) { | ||
time++; | ||
|
||
if (time - que.peek().inTime == W) |
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.
아하!,, 저는 트럭을 ArrayList
에 담아서 시간이 갈 수록 각 트럭의 길이을 +1
로 해준다음 트럭이 간 길이 == 다리 길이
가 될 때 poll
하는 걸로 했는데,
time - 트럭이 터널에 들어간 시간 == W
을 조건으로 해주면 되는군요 ?!?! 😲
제 시간이 다른 분들 시간이 좀 더 걸린 이유가 있었네요,,,
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.
흑 저도 처음엔 트럭이 간길이==다리길이
로 풀었는데 잘 안풀리더라구요...ㅠ 이방법 코드도 다시 한번 확인해봐야겠어요!!
static boolean[][] check; | ||
|
||
private static void movePill(int d, int p){ | ||
p %= N; |
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.
오흐,,, p를 나누기 연산할 생각은 왜 못했을까요,,,,
저는 p를 처음부터 나눌 생각을 못해서 다음 좌표구하는 코드가 x, y 각각 두 줄 씩 있는데,
int nx = ((cur.x + dr[d] * p) + N) % N;
이렇게 한 줄로 나타낼 수 있을 것 같아요!!!!
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.
오호 한 줄표현 감사합니다!!
혹시 삼항연산자 쓰신부분 말씀하시는걸까요..?! 근데 저도 문뜩 int nx = ((cur.x + dr[d] * p) + N) % N;
이렇게 한줄로 표현하면 어짜피 모듈러연산하는데 p를 미리 모듈러했어야하나 생각이 드네요....!?!?!?
for(int i=1; i<8; i+=2){ // 각 영양제의 대각선 체크 (홀수) | ||
int nx = cur.x+dx[i]; | ||
int ny = cur.y+dy[i]; | ||
if((0<=nx && nx<N && 0<=ny && ny<N) && board[nx][ny]>0) board[cur.x][cur.y]++; |
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.
경계 체크하는 부분 같은 경우에는 재사용되는 경우가 많으니 따로 함수로 빼면 좀 더 깔끔해질 것 같아요!
저는 이런식으로 boolean을 반환하도록 사용해요
private static boolean isValid(int ny, int nx) {
return 0 <= nx && nx < N && 0 <= ny && ny < N;
}
private static void movePill(int d, int p){ | ||
p %= N; | ||
int num = pills.size(); | ||
while (!pills.isEmpty() && num-- > 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.
우와 큐를 이용해서 푸는 방법은 전혀 떠올리지 못했었는데, 배워갑니다👍🏻👍🏻
혹시 어떻게 큐 사용하는 방법을 떠올리셨는지, 피드백 시간에 듣고 싶습니다!
No description provided.