Skip to content
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

[트리]11월 22일 #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[트리]11월 22일 #17

wants to merge 1 commit into from

Conversation

aqswa
Copy link
Collaborator

@aqswa aqswa commented Nov 21, 2021

2011번은 어디서 틀리는건지 모르겠습니다! 힌트나 이유 주시면 감사하겠습니다ㅜ

2011번은 어디서 틀리는건지 모르겠습니다! 힌트나 이유 주시면 감사하겠습니다ㅜ
Copy link

@bsa0322 bsa0322 left a comment

Choose a reason for hiding this comment

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

p2. 전반적으로 잘 풀어주셨네요! p2가 붙은 부분은 수정해보시는 걸 추천드려요~!
2011은 아주 사소한 실수네요! 현재 모듈러 연산을 마지막에만 해주시는데, 만약 중간에 dp[i]가 범위를 넘어가는 경우가 생기면 어떻게 될까요?

2011번이랑 나머지 혹시 수정하시면 저 다시 리뷰어로 호출해주세요! 수고하셨습니다!!

Comment on lines +49 to +52
else
return cnt;

return cnt;
Copy link

Choose a reason for hiding this comment

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

p3. 중복되는 코드가 있네요!

Comment on lines +18 to +20
if(r >= 0 && r < n && c >=0 && c < m && board[r][c]==0){
dir = (dir+i)%4;
return true;
Copy link

Choose a reason for hiding this comment

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

p2. clean함수는 주로 board[r][c] == 0일 경우 cnt를 올려주는 역할을 하고 있으니, 이 부분을 수정하면 clean함수의 사용은 꼭 없어도 괜찮을 것 같아요!

더불어 문제의 조건을 잘 읽어보시면, 범위 관련해서 더 간단하게 표현할 수 있어요.

Comment on lines +29 to +31
r -= dx[(dir+2)%4];
c -= dy[(dir+2)%4];
return false;
Copy link

Choose a reason for hiding this comment

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

p2. false를 보내면 clean함수에서 실행되는 명령문을 보니, 불필요한 코드가 보이네요!

Comment on lines +25 to +28
if(t==1 && tree[k] == 1)
cout << "no\n";
else
cout << "yes\n";
Copy link

Choose a reason for hiding this comment

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

p2. 코드가 짧긴 하지만, 이 부분은 함수화를 해도 괜찮겠네요!

Comment on lines +22 to +28
void countSubtreeNodes(int currentNode){
sizee[currentNode] = 1;
for(int i=0; i<tree[currentNode].size(); i++){
countSubtreeNodes(tree[currentNode][i]);
sizee[currentNode] += sizee[tree[currentNode][i]];
}
}
Copy link

Choose a reason for hiding this comment

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

p2. void형 함수는 피해주시는게 좋아요! 이 문제는 특히 리턴형 함수로 바로 답을 반환해줄 수 있어요. 조금 어렵다면 트리 PPT를 참고해보셔도 좋아요! 답이 나와있어요. :)
또한 지금처럼 트리를 만들고 시작해주시는 것도 좋지만, 트리를 만들지 않아도 여기서 트리를 만들 때 사용한 방식으로 탐색을 하면 양방향 그래프로도 트리 탐색 효과를 줄 수 있어요!

Comment on lines +53 to +56
len = s.length();
for(int i=0; i<len; i++){
pw.push_back(s[i]-'0');
}
Copy link

Choose a reason for hiding this comment

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

p2. string을 가공하고 벡터에 넣어서 사용하는 건 조금 비효율적이라, 가급적 string 자체로 사용해주시는 게 좋아요!

Comment on lines +19 to +28
if(pw[1] == 0) {
if (pw[0] < 3)
dp[1] = 1;
}
else{
if(pw[0] == 1 || (pw[0] == 2 && pw[1] < 7))
dp[1] = 2;
else
dp[1] = 1;
}
Copy link

Choose a reason for hiding this comment

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

p2. 1번째 인덱스에 대한 연산을 따로 처리해주느라 중복 코드가 조금 있네요! 이런 경우엔 dp배열의 인덱스를 인덱스 에러가 나지 않도록 관리해주면 해당 연산도 for문 안에서 처리하도록 할 수 있어요! 이때 초기화해주시는 걸 주의해야 해요.

Comment on lines +13 to +23
void divide(int left, int right){
if(left > right)
return;
int root = preorder[left];
int next = left+1;
while(preorder[next] < root && next < preorder.size())
next++;
divide(left+1, next-1);
divide(next, right);
cout << root << '\n';
}
Copy link

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.

2 participants