Skip to content

Week10#10

Open
seoyoung1214 wants to merge 5 commits intomainfrom
week10
Open

Week10#10
seoyoung1214 wants to merge 5 commits intomainfrom
week10

Conversation

@seoyoung1214
Copy link
Copy Markdown
Collaborator

###인적사항
이름 : 김서영
학번 : 2277040

###문제풀이
기존 제출 : 17266, 10815, 16401,2343, 3079

Copy link
Copy Markdown

@avocado8 avocado8 left a comment

Choose a reason for hiding this comment

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

10815(p3)
서영님 안녕하세요 :3 10815번 코드리뷰 드렸습니다.
몇 가지 코멘트 남겨드렸어요. 질문이 있으시다면 언제든 편히 리뷰어를 호출해주세요~

Comment thread BOJ_10815
#include <algorithm>
using namespace std;

int main() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3. 모든 로직이 메인함수에 구현되어 있네요! 이 문제는 짧은 코드로도 구현이 가능하니 괜찮지만, 그래도 최대한 로직별로 함수를 분리하는 것을 추천드립니다 👍

Comment thread BOJ_10815
Comment on lines +26 to +30
if (binary_search(cards.begin(), cards.end(), query[i])) {
cout << "1 ";
} else {
cout << "0 ";
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: 이분 탐색을 사용해 특정 숫자의 존재 여부를 확인하는 로직을 잘 구현해 주셨네요! 다만 공부의 차원에서 라이브러리의 함수를 사용하지 않고 직접 이분 탐색을 구현해 보셔도 좋을 것 같습니다 😊

Comment thread BOJ_10815
}
}

cout << endl;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: 시간 효율을 위해 줄바꿈은 endl보다는 \n을 사용하는 것을 추천드립니다!

Copy link
Copy Markdown
Member

@sforseohn sforseohn left a comment

Choose a reason for hiding this comment

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

[이분탐색 이론 문제 코드 리뷰 완료]

16401(P2, P3)

서영님 안녕하세요! 이번 주도 과제하시느라 고생 많으셨습니다!
어려운 도전문제까지 풀어주시다니 대단합니다😎

몇 가지 코멘트 드렸습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!

Comment thread BOJ_16401
}

int main() {
int numChildren, numSnacks;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P3. 변수명은 스네이크 코드 형식을 따라주세요!

int hello_world;      // 변수
int helloWorld()      // 함수
const int HELLO_WORLD // 상수

Comment thread BOJ_16401
Comment on lines +24 to +25
// 과자의 길이를 내림차순으로 정렬하여 큰 길이부터 탐색하도록 합니다.
sort(snacks.begin(), snacks.end(), greater<int>());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2. 맞아요! 이분탐색을 할 때는 탐색할 값들이 반드시 정렬되어 있어야 한다고 했죠. 🤗 그런데 이 문제에서는 가지고 있는 과자들의 길이 자체는 탐색하지 않으며, 이건 순서에 상관없이 주어진 길이로 과자 몇 개를 나눠줄 수 있는지 계산할 때만 사용돼요. 그래서 lengths를 따로 정렬해주지 않아도 됩니다!

Comment thread BOJ_16401
Comment on lines +27 to +36
int left = 1, right = snacks[0], answer = 0;
while (left <= right) {
int mid = (left + right) / 2;
if (canDivideSnacks(snacks, numChildren, mid)) {
answer = mid; // 가능한 길이이므로 저장
left = mid + 1; // 더 큰 길이를 탐색
} else {
right = mid - 1; // 길이가 부족하면 더 작은 길이를 탐색
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2. 이분 탐색을 하는 부분은 따로 함수로 빼면 좋을 것 같아요~!

Comment thread BOJ_16401
Comment on lines +10 to +12
if (count >= numChildren) return true; // 필요한 아이 수만큼 나눠줄 수 있으면 true
}
return count >= numChildren;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2. 앞의 for문에서 count >= numChildren이면 이미 함수를 빠져나가기 때문에 여기서는 return false;만 적어줘도 될 것 같아요. 🥰

Comment thread BOJ_16401
// 과자의 길이를 내림차순으로 정렬하여 큰 길이부터 탐색하도록 합니다.
sort(snacks.begin(), snacks.end(), greater<int>());

int left = 1, right = snacks[0], answer = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

매개변수 탐색을 위한 초깃값을 잘 설정해주셨네요 💯

Comment thread BOJ_16401
Comment on lines +28 to +36
while (left <= right) {
int mid = (left + right) / 2;
if (canDivideSnacks(snacks, numChildren, mid)) {
answer = mid; // 가능한 길이이므로 저장
left = mid + 1; // 더 큰 길이를 탐색
} else {
right = mid - 1; // 길이가 부족하면 더 작은 길이를 탐색
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

탐색 부분, 함수화 모두 좋습니다! 💯💯💯

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.

3 participants