-
Notifications
You must be signed in to change notification settings - Fork 4
[3주차] 이혜원 #34
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
[3주차] 이혜원 #34
Conversation
for(int i=1; i<N+1; i++){ | ||
Arrays.fill(visited[i], -1); // 카운트 및 방문여부 체크를 위한 초기화 | ||
} | ||
Bfs(); |
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.
저는 말의 위치를 입력받고, bfs하는 순서로 했는데,
bfs먼저 해서 모든 위치에 대해 몇 번째에 이동할 수 있는지 확인하고, 이후에 말의 위치에 대해 몇 번째인지 출력해도 되군요?!! 😲
역시 문제를 풀 때 정해진건 없는거 같네요 ㅎㅎ.. !!
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.
앗 이슈 댓글을 방금 봤는데요,
혜원님이 하신 방법은 주어진 말의 정보에 대해 다 찾아도 탐색이 끝날 때 까지 bfs를 계속 하게 되는데,
다른 분들은 말의 위치까지 map에 다 저장한 이후, 말이 있는 위치에 대해 다 찾으면 bfs를 끝내줘서 이 부분에서 메모리, 시간이 차이나는 것 같아요!
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.
아 그래서 그런거였군요!! 저는 dx, dy를 이차원 배열로 선언해서 그런가 싶어서 일차원배열로 변경 해봤었는데,
오히려 이차원배열로 푼게 시간이 조금 더 빨랐어요 ㅎ,, 다른 분들처럼 탐색이 끝나면 bfs가 멈추는게 더 효율적인 것 같습니다!
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(nX < 1 || nY < 1 || nX > N || nY >N){
continue;
}
OR연산을 AND연산으로 치환해주니 40ms정도 개선되는 것 같더라구요
OR연산은 TRUE가 나올 때까지 연산해서 그런가..봅니다🤔 신기하네요
아니면 백준 컴파일러 차이일 수도!
System.out.println(sb.toString()); | ||
} | ||
private static void Bfs(){ | ||
Queue<Integer> queue = new LinkedList<>(); |
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 j=i; j<10001; j++) { | ||
dp[j] += dp[j-i]; | ||
} | ||
} |
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.
저도 풀이 참고해서 푼거긴한데 이해가 오래 걸렸습니다,,,👍
map[i][j] =1; // 오른쪽 이동 | ||
map[i][j+1] = 2; // 왼쪽 이동 | ||
dfs(i, count+1); // 가로선 하나 추가 -> 재귀 호출 | ||
map[i][j] = map[i][j+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.
백트래킹을 이용해서 유실선을 추가하고 검사하는 로직을 정확히 이해할 수 있는 정석 코드 같아요!!ㅎㅎㅎ 덕분에 이해가 쏙쏙 됐습니다.
for(int i=1; i<N+1; i++){ | ||
Arrays.fill(visited[i], -1); // 카운트 및 방문여부 체크를 위한 초기화 | ||
} | ||
Bfs(); |
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(nX < 1 || nY < 1 || nX > N || nY >N){
continue;
}
OR연산을 AND연산으로 치환해주니 40ms정도 개선되는 것 같더라구요
OR연산은 TRUE가 나올 때까지 연산해서 그런가..봅니다🤔 신기하네요
아니면 백준 컴파일러 차이일 수도!
System.out.println(sum); | ||
} | ||
|
||
public static void simulation(int direction, int pace){ |
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.
메서드를 기능마다 나눠서 리팩토링하는 것도 괜찮을 것 같아요!
월요일
[CT] 디버깅 : DFS, 백트래킹
✔️ 문제 이해 부족 : 메모리 유실선을 반드시 지나가야되는 문제인지 몰랐었음
✔️ DFS, 백트래킹 연습 부족
화요일
[BOJ] 1, 2, 3 더하기4 : DP
✔️ 중복 제거할 때 어려움 겪음
✔️ 점화식 작성 어려움 -> DP 연습 부족
[SQL] 상품 별 오프라인 매출 구하기 : JOIN
✔️ 처음에 풀 때
GROUP BY
사용하지 않았음수요일
[BOJ] 현명한 나이트 : BFS
✔️ BFS 인접 리스트, boolean 배열을 사용해야겠다는 생각에 int 배열을 고려하지 못함
✔️ 문제에서 2차원 배열 구조를 사용하고 있으니 그대로 사용하기
✔️ Arrays.fill(visited[i], -1); // -1로 방문X 초기화
✔️ 범위 확인 항상 고려
[BOJ] 트럭 : Queue
✔️ Queue 사용까진 떠올렸으나, 2개 사용할 생각 못함
✔️ 반복문 구현에 어려움 -> 큐 이용 방법에 익숙해지고 생각 더 많이 하기
목요일
[POG] 징검다리 : 이분탐색
✔️ n값을 보고 이분 탐색을 떠올렸으나 바위 제거를 이분 탐색으로 어떻게 해야될 지 떠올리지 못했음
✔️ mid값 갱신 ㅠ.ㅠ
[SQL] 3월에 태어난 여성 회원 목록 출력하기 : SELECT, NULL
✔️ 조건 여러개 사용해야 할 때 -> AND
✔️ NULL값 제외 출력 -> is not null
금요일
[CT] 나무 타이쿤 : 구현
✔️ 2차원 배열 좌표 매핑[y][x] 공부
✔️ 배열 좌표 갱신에 쫄지말자