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

1-dhlee777 #4

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions dhlee777/bfs/숨바꼭질.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<iostream>
#include<queue>
using namespace std;
int dt[100001]; // �ð�(����)�� �����ϴ� �迭,�ε����� �����̰� �ִ� ��ġ�̴�.
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 dt는 제가 알고있는 Delta Time일까요?
친숙한 단어군요...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

delta time이라는 용어가 있었군요.. 방금 찾아봤는데 게임시간에 관련된용어네요 ..! 저는 그냥 distance를 줄여서 사용했습니다 다음부터는 time_taken 등 더 명확한 표현을 써야겠네요 새로운 단어 잘 알아갑니다 ~!

int k[3] = { -1,1}; //-1,1�� ��ġ�̵��� �����ֱ����� �迭
Copy link
Collaborator

Choose a reason for hiding this comment

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

-1, +1 만 넣었는데 혹시 왜 3으로 배열칸을 잡으셨는지 궁금합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

처음에 *2를 어떻게 처리할지 고민하다가 3칸을 잡아놨었는데 결국 나중에 if문으로 따로 처리해줬습니다 크기를 2로 다시 바꿔줬어야 했는데 깜박했네요.. 좋은 코멘트 감사합니다 !

queue<int>q;

void bfs(int start, int end) {
q.push(start); // ť�� ���� ó�� �������� ������ġ�� �ִ´�.
while (!q.empty()) {
int c = q.front(); //ť���� ��ġ�� ������.
q.pop();
if (c == end) { //ť���� ���� ��ġ�� ������ ��ġ�ϰ��
cout << dt[end]; //������ ã�� ��ġ������ �ּҽð��� ���
return;
}
for (int i = 0; i < 2; i++) { //c�� �����ִ� ��ġ�� ���캻��(-1,+1)
int d = c + k[i]; // -1,+1 �� ��ġ�̵��� ���ذ��� d���ִ´�.
if (d >= 0 && !dt[d] && d <= 100000) { // �湮���� ���� ��ġ�̸� Ž���� �����Ѵ�.
dt[d] = dt[c] + 1; //������ �����ϸ� ���Ž������ġ�� �ð��� ���� ��ġ�ǽð� +1�� ���ش�.
q.push(d); //bfs������ ť�� ��� Ž������ġ�� �ִ´�.
}
}
if (c * 2 <= 100000 && !dt[c * 2]) { //*2�� ���� Ž���� ���
dt[c * 2] = dt[c] + 1; //-1,1�ǰ��� ����
q.push(c * 2);
}
}
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int start,end;
cin >> start >> end; //�������� ������ġ��,������ ������ġ�� �Է¹޴´�.
bfs(start, end);
return 0;
}