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

daisyHyeseul #48

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
75 changes: 74 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
{
"files.associations": {
"iostream": "cpp"
"iostream": "cpp",
"variant": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cuchar": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"scoped_allocator": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp"
}
}
154 changes: 154 additions & 0 deletions WEEK3-A/daisyHyeseul/BOJ14502.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;

int _map[8][8] = {
0,
};
queue<ii> birus;
queue<ii> startbirus;
vector<ii> zero;
int N, M;

int WALL();
int birusCnt(int a[][8]);
int main()
{

ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
//N은 세로크기 M은 가로크기
cin >> N >> M;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cin >> _map[i][j];
if (_map[i][j] == 2)
//확산될 최초 바이러스 저장
startbirus.push(ii(i, j));
if (_map[i][j] == 0)
//벽세울 수 있는 후보 저장
zero.push_back(ii(i, j));
}
}
cout << WALL();
}

//nextpermutation stl을 활용한 벽 세울 수 있는 모든 경우의 수 탐색
int WALL()
{
//원형 보존을 위해 copy
int copymap[8][8];
copy(&_map[0][0], &_map[0][0] + 64, &copymap[0][0]);

//permutation 돌 vector
vector<int> tempVector;

int max = 0;
for (int i = 0; i < 3; i++)
{
tempVector.push_back(1);
}

for (int i = 0; i < zero.size() - 3; i++)
{
tempVector.push_back(0);
}

sort(tempVector.begin(), tempVector.end());

do
{
for (int i = 0; i < tempVector.size(); i++)
{
if (tempVector[i] == 1)
{
//해당조합에 대해서 map에서 벽을 세워줌
copymap[zero[i].first][zero[i].second] = 1;
}
}
//count
int tmp = birusCnt(copymap);
//max update
if (tmp > max)
{
max = tmp;
}
//copymap 초기화
copy(&_map[0][0], &_map[0][0] + 64, &copymap[0][0]);
} while (next_permutation(tempVector.begin(), tempVector.end()));
return max;
}

// BFS를 이용한 바이러스 확산 및 안전구역 개수 세기
int birusCnt(int a[][8])
{
int copymap[8][8];
int count = 0;
//원형 보존을 위한 큐 복사
birus = startbirus;
// 배열도 마찬가지
copy(&a[0][0], &a[0][0] + 64, &copymap[0][0]);

//확산할 바이러스가 없을 때까지
while (!birus.empty())
{
//큐에서 첫번째 원소 좌표 꺼내오기
int x = birus.front().first;
int y = birus.front().second;
birus.pop();
//그 좌표의 상하좌우 검사 후 해당하면 push
if (x < N - 1 && copymap[x + 1][y] == 0)
{
copymap[x + 1][y] = 2;
birus.push(ii(x + 1, y));
}
if (x > 0 && copymap[x - 1][y] == 0)
{
copymap[x - 1][y] = 2;
birus.push(ii(x - 1, y));
}
if (y < M - 1 && copymap[x][y + 1] == 0)
{
copymap[x][y + 1] = 2;
birus.push(ii(x, y + 1));
}
if (y > 0 && copymap[x][y - 1] == 0)
{
copymap[x][y - 1] = 2;
birus.push(ii(x, y - 1));
}
// cout << "\n\n";
// for (int i = 0; i < N; i++)
// {

// for (int j = 0; j < M; j++)
// {
// cout << copymap[i][j] << " ";
// if (copymap[i][j] == 2)
// {
// count++;
// }
// }
// cout << "\n";
// }
}
// cout << "\n\n";

//0의 개수 세기 (안전구역 면적 구하기)
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
// cout << copymap[i][j] << " ";
if (copymap[i][j] == 0)
{
count++;
}
}
// cout << "\n";
}
return count;
}
85 changes: 85 additions & 0 deletions WEEK3-A/daisyHyeseul/BOJ2206.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
int N, M;
queue<iii> q;
int visited[1000][1000][2] = {
0,
}; //visited는 해당 정점까지의 최단경로를 저장하며, 2는 오는 동안 벽을 부순 세계와 안 부순 세계로 나누는 역할
int _map[1000][1000] = {
0,
};
void printArray(int a[][1000]);
void BFS();
int main()
{

cin >> N >> M;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
scanf("%1d", &_map[i][j]);
}
}
BFS();
}

void printArray(int a[][1000])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cout << a[i][j] << " ";
}
cout << "\n";
}
cout << "\n\n";
}
void BFS()
{
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

q.push(iii(ii(0, 0), 0));
visited[0][0][0] = 1;

while (!q.empty())
{
// printArray(visited);
iii tmp = q.front();
q.pop();
if (tmp.first.first == N - 1 && tmp.first.second == M - 1)
{
cout << visited[tmp.first.first][tmp.first.second][tmp.second];
return;
}
for (int i = 0; i < 4; i++)
{
int nx = tmp.first.first + dx[i];
int ny = tmp.first.second + dy[i];
if ((nx < 0) || (ny < 0) || (nx >= N) || (ny >= M))
continue;
if (visited[nx][ny][tmp.second] == 0)
{
//해당 공간이 비었다면 기존 벽뚫기 여부 그대로 가지고 거리만 +1
if (_map[nx][ny] == 0)
{
q.push(iii(ii(nx, ny), tmp.second));
visited[nx][ny][tmp.second] = visited[tmp.first.first][tmp.first.second][tmp.second] + 1;
}

//해당 공간이 벽이고, 벽 뚫은 적이 없다면, 벽뚫고 거리 +1
else if (_map[nx][ny] == 1 && tmp.second == 0)
{
q.push(iii(ii(nx, ny), 1));
visited[nx][ny][1] = visited[tmp.first.first][tmp.first.second][tmp.second] + 1;
}
}
}
}
cout << -1;
return;
}
46 changes: 46 additions & 0 deletions WEEK3-A/daisyHyeseul/BOJ5567.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <bits/stdc++.h>
using namespace std;
vector<int> relation[502]; //친구관계를 저장하는 벡터 배열(사실상 이차원 배열)
int _visit[502] = {
0,
}; //i번째 사람의 결혼식 방문 여부를 저장하는 배열

void findFriends();
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
int count = 0;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
//a와 b가 친구라면 서로의 친구 list(vector)에 서로를 넣어준다.
relation[a].push_back(b);
relation[b].push_back(a);
}
findFriends();
for (int i = 2; i <= n + 1; i++)
//1은 상근이 본인이므로 2번째 사람부터 탐색하여 결혼식 참여 인원을 센다.
{
if (_visit[i])
count++;
}
cout << count;
}

void findFriends()
{
for (int i = 0; i < relation[1].size(); i++) //상근이 친구 탐색
{
int tmp = relation[1][i];
_visit[tmp] = 1; //상근이 친구는 무조건 참석
for (int j = 0; j < relation[tmp].size(); j++) //친구의 친구 탐색
{
_visit[relation[tmp][j]] = 1;
}
}
}
Loading