-
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.
μ ν¨μλ§ λ°μΌλ‘ λΊμλ μμκ΅°μ.. μ½λκ° ν¨μ¬κΉλν΄μ§λκ±° κ°μ΅λλ€. μμ¨λ¨Ήκ² μ΅λλ€ !