-
Notifications
You must be signed in to change notification settings - Fork 1
18-hadongun #75
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
18-hadongun #75
Conversation
dohyeondol1
left a comment
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.
μ νμ μΈ κ·Έλν νμ λ¬Έμ λ€μ!
μ λ λμ€λμ²λΌ bfsλ₯Ό μ¬μ©νμ¬ νμμ΅λλ€.
C++
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N, M;
vector<string> campus;
bool visited[601][601];
int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, -1, 1 };
int bfs(int startX, int startY) {
queue<pair<int, int>> q;
q.push({startX, startY});
visited[startX][startY] = true;
int count = 0;
while(!q.empty()) {
auto [x, y] = q.front();
q.pop();
if(campus[x][y] == 'P') count++;
for(int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
if(visited[nx][ny] || campus[nx][ny] == 'X') continue;
visited[nx][ny] = true;
q.push({nx, ny});
}
}
return count;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> N >> M;
campus.resize(N);
int startX, startY;
for(int i = 0; i < N; i++) {
cin >> campus[i];
for(int j = 0; j < M; j++) {
if(campus[i][j] == 'I') {
startX = i;
startY = j;
}
}
}
int result = bfs(startX, startY);
if(result == 0) cout << "TT" << '\n';
else cout << result << '\n';
return 0;
}ν¨μλͺ
μ μ§μ λ, κ°κ°μΈμ μ€νμΌμ λ°λΌ λ€λ₯΄μ§λ§ κ° λ¨μ΄ λ¨μλ‘ λμλ¬Έμλ λμ΄μ°κΈ°, μΈλλ° λ±μ μ¬μ©ν΄ ꡬλΆμ μ§μ΄μ£Όλ©΄ κ°λ
μ±μ κ°μ νλλ°μ μ½κ°μ λμμ μ€λλ©.
λ€μ΄λ° 컨벀μ
μ΄λΌκ³ , μ¬λ¬ μ’
λ₯κ° μμΌλ λ§λ μ€νμΌμ μ¬μ©ν΄λ³΄λκ²λ μΆμ²λ립λλ€.
| μμ | μ΄λ¦(λ€) |
|---|---|
| twowords | νλ«μΌμ΄μ€ |
| TWOWORDS | λλ¬Έμ, μλ¬Έμ |
| twoWords | camelCase, dromedaryCase |
| TwoWords | PascalCase, UpperCamelCase |
| two_words | λ± μΌμ΄μ€, λ¬ν½μ΄ μΌμ΄μ€, μνΉ λ€μ΄κ° κ³³ μΌμ΄μ€ |
| TWO_WORDS | ALL_CAPS, SCREAMING_SNAKE_CASE, MACRO_CASE, CONSTANT_CASE |
| two_Words | λν_λ±_μΌμ΄μ€ |
| Two_Words | Pascal_Snake_Case, Title_Case |
| two-words | μΌλ°₯ μΌμ΄μ€, λμ μΌμ΄μ€, 리μ€ν μΌμ΄μ€, μ€νμΈ μΌμ΄μ€ |
| TWO-WORDS | κΈ°μ°¨ μΌμ΄μ€, μ½λ³Ό μΌμ΄μ€, λΉλͺ μΌλ°₯ μΌμ΄μ€ |
| Two-Words | Train-Case, HTTP-Header-Case |
무μλ³΄λ€ μκΈ°κ° κ°μ₯ μ μμλ³Ό μ μμΌλ©΄ λ©λλ€!
|
μ λ κ°λ¨ν BFSλ₯Ό μ΄μ©ν΄ μ΄ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ€ γ γ import sys
from collections import deque
input = sys.stdin.readline
n, m = map(int, input().split())
campus = [list(input().rstrip()) for _ in range(n)]
start = None
for i in range(n):
for j in range(m):
if campus[i][j] == "I":
start = (i, j)
break
if start is not None:
break
visited = [[False]*m for _ in range(n)]
q = deque([start])
visited[start[0]][start[1]] = True
meet_count = 0
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
while q:
r, c = q.popleft()
for d in range(4):
nr, nc = r + dr[d], c + dc[d]
if 0 <= nr < n and 0 <= nc < m:
if not visited[nr][nc] and campus[nr][nc] != 'X':
visited[nr][nc] = True
if campus[nr][nc] == 'P':
meet_count += 1
q.append((nr, nc))
if meet_count:
print(meet_count)
else:
print("TT") |
|
μ λ 무λνκ² bfsλ‘ νμμ΅λλ€! #include <iostream>
#include <vector>
#include <queue>
#define X first
#define Y second
using namespace std;
int dx[4] = {0, 0,-1, 1};
int dy[4] = {-1, 1, 0, 0};
void bfs(vector<string> &cam, pair<int, int> iPos,int n, int m)
{
vector<vector<int> > board(n, vector<int>(m, 0));
queue<pair<int, int> > q;
pair<int, int> cur;
int nx, ny, cnt=0;
q.push(iPos);
while (!q.empty())
{
cur = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
nx = cur.X + dx[i]; ny = cur.Y + dy[i];
if (nx < 0 || nx >= n || ny < 0 || ny >= m ||
board[nx][ny] == 1 || cam[nx][ny] == 'X')
continue;
if (cam[nx][ny] == 'P') cnt++;
board[nx][ny] = 1;
q.push(make_pair(nx, ny));
}
}
if (cnt==0) cout << "TT";
else cout << cnt;
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<string> cam(n, "");
pair<int, int> iPos;
for (int i = 0; i < n; i++)
{
cin >> cam[i];
for (int j= 0; j < m; j++)
{
if (cam[i][j] == 'I')
{
iPos = make_pair(i, j);
}
}
}
bfs(cam, iPos,n, m);
}
|
π λ¬Έμ λ§ν¬
νλ΄κΈ°λ μΉκ΅¬κ° νμν΄
βοΈ μμλ μκ°
30min
β¨ μλ μ½λ
μλ νμΈμ. λμ΄ μ¬λ¦μ λλ€.

μ΄λ² λ¬Έμ λ 'μ λ§λ€ μ°μ°!!!' κ³Ό λΉμ·ν λ¬Έμ μ λλ΅
λ°©λ¬Έν μ μλ λͺ¨λ μ¬λμ μ°Ύμ μ μΉκ΅¬λ‘ λ§λ€μ΄λ²λ¦¬κ² μ΅λλ€.
μμ μ§μ μ°ΎκΈ°
μ°μ μμ μ§μ μ μ°ΎκΈ° μν΄μ selflocation ν¨μλ₯Ό μ μ‘°νμ΅λλ€.
λͺ¨λ λΆλΆμ λλ©΄μ μμ μ§μ μμΉμΈ 'I' λ₯Ό μ°Ύκ³ κ·Έ μ’ν κ°μ ννμ ννλ‘ λ°ννμμ¨λΉ
μΉκ΅¬ λ§λ€κΈ°
μΉκ΅¬λ₯Ό λ§λ€μ΄μΌκ² μ£ !
μλμ½λ
μ€λλ λμ°μ΄μ μΉκ΅¬λ₯Ό λ§λ€μ΄μ£Όμμ΅λλ€. κ°μ¬ν©λλ€
μ€λλ λ΄μΌλ νλ΄μκΈΈ λ°λΌκ² μ΅λλ€.
π μλ‘κ² μκ²λ λ΄μ©