Skip to content

Commit 757c33c

Browse files
authored
2022_15_정환훈
2022_15_정환훈
1 parent b960ba6 commit 757c33c

File tree

4 files changed

+259
-0
lines changed

4 files changed

+259
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int n; int m;
5+
int in[32001];
6+
vector<int> adj[32001];
7+
void input() {
8+
cin >> n >> m;
9+
for (int i = 0; i < m; i++) {
10+
int a; int b;
11+
cin >> a >> b;
12+
adj[a].push_back(b);
13+
in[b]++;
14+
}
15+
}
16+
17+
18+
void solve() {
19+
priority_queue<int, vector<int>, greater<int>> q;
20+
for (int i = 1; i <= n; i++) {
21+
if (in[i] == 0) {
22+
q.push(i);
23+
}
24+
}
25+
26+
while (!q.empty()) {
27+
int cur = q.top();
28+
q.pop();
29+
cout << cur << " ";
30+
for (int i = 0; i < adj[cur].size(); i++) {
31+
in[adj[cur][i]]--;
32+
if (in[adj[cur][i]] == 0)
33+
q.push(adj[cur][i]);
34+
}
35+
}
36+
37+
38+
}
39+
40+
41+
int main(void) {
42+
ios_base::sync_with_stdio(0);
43+
cin.tie(0);
44+
cout.tie(0);
45+
46+
input();
47+
solve();
48+
49+
return 0;
50+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int n;
5+
char board[64][64];
6+
7+
void input() {
8+
cin >> n;
9+
for (int i = 0; i < n; i++) {
10+
for (int j = 0; j < n; j++) {
11+
cin >> board[i][j];
12+
}
13+
}
14+
}
15+
16+
void check(int i, int j, int depth) {
17+
18+
if (depth == 0) {
19+
cout << board[i][j];
20+
return;
21+
}
22+
23+
int size = pow(2, depth);
24+
bool cut = false;
25+
for (int a = i; a < i + size; a++) {
26+
for (int b = j; b < j + size; b++) {
27+
if (a >= n || b >= n || board[i][j] != board[a][b]) {
28+
cut = true;
29+
break;
30+
}
31+
}
32+
if (cut) break;
33+
}
34+
35+
if (cut) {
36+
cout << "(";
37+
check(i, j, depth - 1);
38+
check(i, j + size/2, depth - 1);
39+
check(i + size/2, j, depth - 1);
40+
check(i + size/2, j + size/2, depth - 1);
41+
cout << ")";
42+
}
43+
else
44+
cout << board[i][j];
45+
}
46+
47+
48+
void solve() {
49+
int sq = 0; int temp = n;
50+
while (temp) {
51+
temp = temp / 2;
52+
sq++;
53+
}
54+
sq--;
55+
check(0, 0, sq);
56+
}
57+
58+
59+
int main(void) {
60+
ios_base::sync_with_stdio(0);
61+
cin.tie(0);
62+
cout.tie(0);
63+
64+
input();
65+
solve();
66+
67+
return 0;
68+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
int n; int m; vector<int> a;
7+
8+
void input() {
9+
cin >> n >> m;
10+
for (int i = 0; i < n; i++) {
11+
int temp;
12+
cin >> temp;
13+
a.push_back(temp);
14+
}
15+
}
16+
17+
void solve() {
18+
sort(a.begin(), a.end());
19+
int l = 0; int r = 0;
20+
int ans = 2000000001;
21+
while (l < n && r < n) {
22+
if (a[r] - a[l] == m) {
23+
cout << m;
24+
return;
25+
}
26+
if (a[r] - a[l] < m) {
27+
r++;
28+
}
29+
else {
30+
ans = min(ans, a[r] - a[l]);
31+
l++;
32+
}
33+
34+
}
35+
cout << ans;
36+
}
37+
38+
int main() {
39+
ios_base::sync_with_stdio(0);
40+
cin.tie(0);
41+
cout.tie(0);
42+
input();
43+
solve();
44+
45+
return 0;
46+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// (-1,-1) (0,-1) (1,0) (0,1) (-1,1) (-1,0)
5+
// (0,-1) (1,-1) (1,0) (1,1) (0,1) (-1,0)
6+
7+
pair<int, int> even[6] = { {-1,-1}, {0,-1}, {1,0}, {0,1}, {-1,1}, {-1,0} };
8+
pair<int, int> odd[6] = { {0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,0} };
9+
10+
int w; int h;
11+
int ans = 0;
12+
int board[102][102];
13+
bool v[102][102];
14+
void input() {
15+
cin >> w >> h;
16+
for (int i = 0; i < 101; i++) {
17+
for (int j = 0; j < 101; j++) {
18+
board[i][j] = -1;
19+
}
20+
}
21+
for (int i = 1; i <= h; i++) {
22+
for (int j = 1; j <= w; j++) {
23+
cin >> board[j][i];
24+
}
25+
}
26+
27+
}
28+
29+
void bfs(int i, int j) { // 0,0부터 시작해서 만질 수 있는 벽들 개수 세기
30+
v[i][j] = true;
31+
queue<pair<int, int>> q;
32+
int walls = 0;
33+
q.push({ i,j });
34+
while (!q.empty()) {
35+
pair<int, int> now = q.front();
36+
int x = now.first;
37+
int y = now.second;
38+
q.pop();
39+
if (y % 2 == 0) {
40+
for (int k = 0; k < 6; k++) {
41+
int ny = y + even[k].second;
42+
int nx = x + even[k].first;
43+
if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) {
44+
if (board[nx][ny] == -1 && !v[nx][ny]) {
45+
v[nx][ny] = true;
46+
q.push({ nx,ny });
47+
}
48+
if (board[nx][ny] == 1)
49+
walls++;
50+
if (board[nx][ny] == 0 && !v[nx][ny]) {
51+
v[nx][ny] = true;
52+
q.push({ nx,ny });
53+
}
54+
}
55+
}
56+
}
57+
else {
58+
for (int k = 0; k < 6; k++) {
59+
int ny = y + odd[k].second;
60+
int nx = x + odd[k].first;
61+
if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) {
62+
if (board[nx][ny] == -1 && !v[nx][ny]) {
63+
v[nx][ny] = true;
64+
q.push({ nx,ny });
65+
}
66+
if (board[nx][ny] == 1)
67+
walls++;
68+
if (board[nx][ny] == 0 && !v[nx][ny]) {
69+
v[nx][ny] = true;
70+
q.push({ nx,ny });
71+
}
72+
}
73+
}
74+
}
75+
}
76+
ans += walls;
77+
78+
}
79+
80+
void solve() {
81+
bfs(0, 0);
82+
cout << ans;
83+
}
84+
85+
86+
int main(void) {
87+
ios_base::sync_with_stdio(0);
88+
cin.tie(0);
89+
cout.tie(0);
90+
91+
input();
92+
solve();
93+
94+
return 0;
95+
}

0 commit comments

Comments
 (0)