Skip to content

Commit

Permalink
2022_15_정환훈
Browse files Browse the repository at this point in the history
2022_15_정환훈
  • Loading branch information
ParangBird authored Aug 24, 2022
1 parent b960ba6 commit 757c33c
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 0 deletions.
50 changes: 50 additions & 0 deletions 2022/16주차/정환훈/1766_문제집.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;

int n; int m;
int in[32001];
vector<int> adj[32001];
void input() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a; int b;
cin >> a >> b;
adj[a].push_back(b);
in[b]++;
}
}


void solve() {
priority_queue<int, vector<int>, greater<int>> q;
for (int i = 1; i <= n; i++) {
if (in[i] == 0) {
q.push(i);
}
}

while (!q.empty()) {
int cur = q.top();
q.pop();
cout << cur << " ";
for (int i = 0; i < adj[cur].size(); i++) {
in[adj[cur][i]]--;
if (in[adj[cur][i]] == 0)
q.push(adj[cur][i]);
}
}


}


int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

input();
solve();

return 0;
}
68 changes: 68 additions & 0 deletions 2022/16주차/정환훈/1992_쿼드트리.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <bits/stdc++.h>
using namespace std;

int n;
char board[64][64];

void input() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> board[i][j];
}
}
}

void check(int i, int j, int depth) {

if (depth == 0) {
cout << board[i][j];
return;
}

int size = pow(2, depth);
bool cut = false;
for (int a = i; a < i + size; a++) {
for (int b = j; b < j + size; b++) {
if (a >= n || b >= n || board[i][j] != board[a][b]) {
cut = true;
break;
}
}
if (cut) break;
}

if (cut) {
cout << "(";
check(i, j, depth - 1);
check(i, j + size/2, depth - 1);
check(i + size/2, j, depth - 1);
check(i + size/2, j + size/2, depth - 1);
cout << ")";
}
else
cout << board[i][j];
}


void solve() {
int sq = 0; int temp = n;
while (temp) {
temp = temp / 2;
sq++;
}
sq--;
check(0, 0, sq);
}


int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

input();
solve();

return 0;
}
46 changes: 46 additions & 0 deletions 2022/16주차/정환훈/2230_수 고르기.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n; int m; vector<int> a;

void input() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
a.push_back(temp);
}
}

void solve() {
sort(a.begin(), a.end());
int l = 0; int r = 0;
int ans = 2000000001;
while (l < n && r < n) {
if (a[r] - a[l] == m) {
cout << m;
return;
}
if (a[r] - a[l] < m) {
r++;
}
else {
ans = min(ans, a[r] - a[l]);
l++;
}

}
cout << ans;
}

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solve();

return 0;
}
95 changes: 95 additions & 0 deletions 2022/16주차/정환훈/5547_일루미네이션.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <bits/stdc++.h>
using namespace std;

// (-1,-1) (0,-1) (1,0) (0,1) (-1,1) (-1,0)
// (0,-1) (1,-1) (1,0) (1,1) (0,1) (-1,0)

pair<int, int> even[6] = { {-1,-1}, {0,-1}, {1,0}, {0,1}, {-1,1}, {-1,0} };
pair<int, int> odd[6] = { {0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,0} };

int w; int h;
int ans = 0;
int board[102][102];
bool v[102][102];
void input() {
cin >> w >> h;
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 101; j++) {
board[i][j] = -1;
}
}
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> board[j][i];
}
}

}

void bfs(int i, int j) { // 0,0부터 시작해서 만질 수 있는 벽들 개수 세기
v[i][j] = true;
queue<pair<int, int>> q;
int walls = 0;
q.push({ i,j });
while (!q.empty()) {
pair<int, int> now = q.front();
int x = now.first;
int y = now.second;
q.pop();
if (y % 2 == 0) {
for (int k = 0; k < 6; k++) {
int ny = y + even[k].second;
int nx = x + even[k].first;
if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) {
if (board[nx][ny] == -1 && !v[nx][ny]) {
v[nx][ny] = true;
q.push({ nx,ny });
}
if (board[nx][ny] == 1)
walls++;
if (board[nx][ny] == 0 && !v[nx][ny]) {
v[nx][ny] = true;
q.push({ nx,ny });
}
}
}
}
else {
for (int k = 0; k < 6; k++) {
int ny = y + odd[k].second;
int nx = x + odd[k].first;
if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) {
if (board[nx][ny] == -1 && !v[nx][ny]) {
v[nx][ny] = true;
q.push({ nx,ny });
}
if (board[nx][ny] == 1)
walls++;
if (board[nx][ny] == 0 && !v[nx][ny]) {
v[nx][ny] = true;
q.push({ nx,ny });
}
}
}
}
}
ans += walls;

}

void solve() {
bfs(0, 0);
cout << ans;
}


int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

input();
solve();

return 0;
}

0 comments on commit 757c33c

Please sign in to comment.