-
Notifications
You must be signed in to change notification settings - Fork 4
[3주차] 백제완 #30
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주차] 백제완 #30
Conversation
ladders[y - 1][x - 1] = true; | ||
} | ||
// 사다리를 3개 이하로 설치해서 올바른지 확인 | ||
for (int i = 0; i <= 3; 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.
사다리를 3개까지만 설치한다고 가정하고 시뮬레이션을 돌리는게 효과적인 것 같습니다! 👍
for (int i = 0; i < h; i++) { | ||
for (int j = 0; j < n - 1; j++) { | ||
// 사다리를 설치할 수 있는 위치라면 | ||
if (isPossible(i, j)) { |
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.
@KodaHye
구현은.. 저도 잘 못하지만 칭찬해주셔서 감사합니다🤓
어떻게 하면 한번에 많은 조건을 처리할 수 있을까?
를 생각을 자주 하면서 문제를 풀고 있어요!
그래서 최대한 묶을 수 있는 것들은 묶어서 처리하다보니 간단해진 것 같습니다👍🏻
n = read(); | ||
int m = read(); | ||
int x = read(), y = read(); // 초기 나이트 | ||
int[][] EArr = new int[m][2]; // 상대 말의 위치를 저장할 배열 |
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.
@KodaHye
이 부분은 저도 항상 코드 작성할 때 고민하는 부분입니다!
일단 저는 자료형이 같고, 단순한 정보(좌표)를 저장할 때는 배열을 주로 이용하는 편이에요!
제가 배열을 주로 사용하는 이유를 생각해봤는데
- 코드 작성이 간단하다
- 나만 알아보면 문제 없다 (인덱스가 뭘 지칭하는지는 따로 적어둠)
밖에.. 없는 것 같네요..🤔 아무래도 코딩테스트를 위한 코드니깐 빠르게 작성하려고 그런 것 같아요!
많은 조건을 저장해야하는 경우에는 클래스를 만들어 씁니다!
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 문제 풀이를 보면 Class 나 배열을 사용하는 코드가 있었는데, 둘의 사용했을 때 어떤 차이가 있는지 궁금했었어요!
개인적으로 저는 Class 를 사용했을때 해당 위치를 index 로 이해하지 않고 객체 자체로 이해하니까 더 가독성이 좋고 디버깅을 할때도 이해하기 편했던거 같아요 ㅎㅎ
이번에 BFS를 풀 때 처음으로 Class 를 이용해서 풀어봤는데,
클래스로 생각하니까 현재 위치에 도달했을 때 어떤 정보를 얻을 수 있는지 객체의 필드에 저장할 수 있어서 조금 더 유연성 있는 생각을 할 수 있었던것 같습니다!
} | ||
|
||
// 사다리를 설치할 수 있는지 없는지 확인 | ||
private static boolean isPossible(int y, int 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.
위에서 말씀하신 것처럼 배열로 구현하니까 확실히 깔끔하군요!
확인할 위치에서 딱 왼쪽, 오른쪽만 확인하면되네요..
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.