-
Notifications
You must be signed in to change notification settings - Fork 0
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월 15일 #15
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uB3D9\uC801\uACC4\uD68D\uBC95\uACFC-\uCD5C\uB2E8\uAC70\uB9AC-\uC5ED\uCD94\uC801"
Conversation
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.
p2. 전반적으로 잘 풀어주셨네요! 특히 택배문제와 플로이드2 문제 아주 잘 풀어주셨어요!! 👍 p2가 붙은 코멘트들은 수정해보셔도 좋을 것 같아요~! 특히 오목 문제는 방향 배열을 활용하면 지금보다 훨씬 가독성 좋은 코드로 리팩토링할 수 있으니 수정해보시는 걸 추천드립니다!
수정하신다면, 저 다시 리뷰어로 호출해주세요. 수고하셨습니다 :)
+ 감시 문제는 추가제출해주시는 거려나요? 혹 힌트 필요하시거나 풀어서 제출하신다면 저 다시 리뷰어로 호출해주세요!
cout << table[i][j].first+1 << ' ' << i << ' '; | ||
int t = table[i][j].second; | ||
while(t != j){ | ||
cout << t << ' '; | ||
t = table[t][j].second; | ||
} | ||
cout << 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.
p3. 우선 택배 문제를 활용해서 경로 추적해주신 거 아주 좋아요!! 👍
지금처럼 크기를 따로 table에 저장하며 풀어주신 것도 좋지만, 경로를 추적한 결과값을 배열에 담은 후 나중에 배열 사이즈와 원소를 출력해도 괜찮겠네요! 그럼 table에 들어가는 메모리를 줄일 수 있을 거예요.
if (count[i / 3].first == 0) | ||
count[i / 3] = {count[i].first + 1, i}; | ||
else { | ||
if (count[i / 3].first > count[i].first + 1) | ||
count[i / 3] = {count[i].first + 1, 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.
p2. count[i].first의 값을 문제의 입력범위보다 큰 상수를 선언해서 초기화하면 현재 코드를 하나로 합칠 수 있겠네요!! 나머지 i % 2 와 i - 1에 대해서도요~! 더불어 메인 연산을 하고 있는 부분은 함수화를 하면 더 좋을 것 같아요!
for (int i = 0; i < ans; i++) | ||
path[i + 1] = count[path[i]].second; |
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.
p2. 역추적 부분도 함수화할 수 있겠네요~!
if(graph[u][v] > w){ | ||
graph[u][v] = w; | ||
graph[v][u] = w; | ||
table[u][v] = v; | ||
table[v][u] = u; | ||
} |
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.
p3. 혹시 모를 중복 간선을 항상 걸러주는 것도 좋지만, 문제에서 주어진 정점과 간선의 최대범위를 보고, 정점에 대한 최대 간선을 계산해보면 중복 간선이 들어오는지 안 들어오는지 파악할 수 있어요~! 그래도 코딩테스트에선 시간이 없을 수 있으니 항상 걸러주는 것도 괜찮겠네요!
vector<vector<int>> board(20, vector<int>(20)); | ||
for(int i=1; i<20; 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.
p2. 20은 앞으로 계속 사용할 테니, 헷갈리지 않게 상수로 선언하고 사용해주시는 게 좋아요!
if(color == 1) { | ||
check = five(1, i, j, board); | ||
if(check) { | ||
cout << color << '\n' << i << ' ' << j; | ||
return 0; | ||
} | ||
} | ||
else if(color == 2){ | ||
check = five(2, i, j, board); | ||
if(check){ | ||
cout << color << '\n' << i << ' ' << j; | ||
return 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.
p2. 이 부분은 color만 다르고 연산은 중복되니, 하나로 합칠 수 있겠네요~!
for(int k = 1; k < 5; k++){ | ||
if(j>15 || board[i][j+k] != color){ | ||
check = false; | ||
break; | ||
} | ||
} | ||
if(check){ | ||
if((j==1 || board[i][j-1] != color) && (j==15 || board[i][j+5] != color)) | ||
return true; | ||
} | ||
|
||
check = true; | ||
for (int k = 1; k < 5; k++) { | ||
if(i>15 || board[i+k][j] != color){ | ||
check = false; | ||
break; | ||
} | ||
} | ||
if(check){ | ||
if((i==1 || board[i-1][j] != color) && (i==15 || board[i+5][j] != color)) | ||
return true; | ||
} | ||
|
||
check = true; | ||
for(int k = 1; k < 5; k++){ | ||
if(i>15 || j>15 || board[i+k][j+k] != color){ | ||
check = false; | ||
break; | ||
} | ||
} | ||
if(check){ | ||
if((i==1 || j==1 || board[i-1][j-1] != color) && (i==15 || j==15 || board[i+5][j+5] != color)) | ||
return true; | ||
} | ||
|
||
check = true; | ||
for(int k=1; k<5; k++){ | ||
if(i<5 || j>15 || board[i-k][j+k] != color){ | ||
check = false; | ||
break; | ||
} | ||
} | ||
if(check){ | ||
if((i==1 || j==19 || board[i+1][j-1] != color) && (i==5 || j==15 || board[i-5][j+5] != color)) | ||
return true; | ||
} |
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.
p2. 가능한 방향에 대한 배열을 미리 만든 후, 반복문을 통해 관리하면 현재 연산을 훨씬 짧게 줄일 수 있어요! 방향 배열을 다루는 문제는 지금까지 꽤 해봤어요. 한 번 수정해볼까요!
No description provided.