-
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
10-dhlee777 #47
Merged
Merged
10-dhlee777 #47
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include<iostream> | ||
#include<queue> | ||
using namespace std; | ||
int tom[101][101][101]; //�丶���� ���¸� �����ϱ����� �迭 | ||
int col, row, height; | ||
int x[6] = { 0,0,-1,1,0,0 }; | ||
int y[6] = { -1,1,0,0,0,0 }; | ||
int z[6] = { 0,0,0,0,1,-1 }; | ||
struct tomato { //�丶���� ��ǥ�� �����ϱ����� ����ü | ||
int x1; //�� | ||
int y1; //�� | ||
int z1; //���� | ||
tomato(int _x1, int _y1, int _z1) { | ||
x1 = _x1; y1 = _y1; z1 = _z1; | ||
|
||
} | ||
}; | ||
queue<tomato>q; | ||
void bfs() { | ||
while (!q.empty()) { | ||
tomato t = q.front(); | ||
q.pop(); | ||
for (int i = 0; i < 6; i++) { //Ž������(��,��,��,��,��,�Ʒ�) | ||
int _x = t.x1 + x[i]; | ||
int _y = t.y1 + y[i]; | ||
int _z = t.z1 + z[i]; | ||
if (_x < col && _x >= 0 && _y < row && _y >= 0 && _z < height && _z >= 0 && tom[_z][_y][_x] == 0) { | ||
tom[_z][_y][_x] = tom[t.z1][t.y1][t.x1] + 1; | ||
q.push(tomato(_x, _y, _z)); | ||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cin >> col >> row >> height; | ||
|
||
for (int i = 0; i < height; i++) { | ||
for (int j = 0; j < row; j++) { | ||
for (int k = 0; k < col; k++) { | ||
cin >> tom[i][j][k]; | ||
if (tom[i][j][k] == 1) //�����丶�䰡 ��������� | ||
q.push(tomato(k, j, i)); //Ž�������������� �� ��ǥ�� ť�� �ִ´�. | ||
} | ||
} | ||
} | ||
|
||
bfs(); // | ||
int sum = 0; | ||
for (int i = 0; i < height; i++) { | ||
for (int j = 0; j < row; j++) { | ||
for (int k = 0; k < col; k++) { | ||
if (tom[i][j][k] == 0) //bfs�� �������丶�䰡 �ִٸ� ����������ϴ� ��Ȳ�̹Ƿ� -1�� ��� | ||
{ | ||
cout << -1; | ||
return 0; | ||
} | ||
if (sum < tom[i][j][k]) sum = tom[i][j][k]; //bfs �� �ɸ��ð��� ã������ tom�迭�� �ִ밪�� ã�� sum�� �����ϴ°��� | ||
|
||
} | ||
} | ||
} | ||
|
||
sum == 1 ? cout << 0 : cout << sum - 1; | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
아 함수만 밖으로 뺄수도 있었군요.. 코드가 훨씬깔끔해지는거 같습니다. 잘써먹겠습니다 !