Skip to content

Commit c138bce

Browse files
committed
Solve some problems
1 parent a94d20f commit c138bce

12 files changed

Lines changed: 478 additions & 66 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
dif
22
# Created by https://www.gitignore.io/api/c++,osx,clion,emacs,clion+all
33
# Edit at https://www.gitignore.io/?templates=c++,osx,clion,emacs,clion+all
44

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"string_view": "cpp",
1919
"unordered_map": "cpp",
2020
"utility": "cpp",
21-
"tuple": "cpp"
21+
"tuple": "cpp",
22+
"algorithm": "cpp",
23+
"stdexcept": "cpp",
24+
"ios": "cpp"
2225
}
2326
}

boj/10989/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import sys
2+
import collections
3+
h = collections.defaultdict(int)
4+
5+
input = sys.stdin.readline
6+
n = int(input())
7+
8+
for _ in range(n):
9+
h[int(input())] += 1
10+
11+
12+
for i in range(1, 10000+1):
13+
for _ in range(h[i]):
14+
print(i)

boj/13398/main.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@ int d1[100002];
99
int d2[100002];
1010
int a[100001];
1111

12-
int main() {
12+
int main()
13+
{
1314
ios::sync_with_stdio(false);
1415
cin.tie(NULL);
1516
cout.tie(NULL);
17+
1618
int n;
1719
cin >> n;
18-
for (int i = 1; i <= n; i++) {
20+
for (int i = 1; i <= n; i++)
21+
{
1922
cin >> a[i];
2023
}
24+
d1[1] = a[1];
2125

22-
for (int i = 1; i <= n; i++) {
26+
for (int i = 2; i <= n; i++)
27+
{
2328
d1[i] = a[i];
24-
25-
if ((d1[i - 1] + a[i]) > a[i]) {
26-
d1[i] = d1[i - 1] + a[i];
27-
}
28-
}
29-
30-
for (int i = n; i > 0; i--) {
31-
d2[i] = a[i];
32-
33-
if ((d2[i + 1] + a[i]) > a[i]) {
34-
d2[i] = d2[i + 1] + a[i];
29+
if ((d1[i - 1] + d1[i]) > d1[i])
30+
{
31+
d1[i] = d1[i - 1] + d1[i];
3532
}
3633
}
3734

3835
int max = d1[1];
39-
for (int i = 1; i <= n; i++) {
40-
if ((d1[i - 1] + d2[i + 1]) > max) {
36+
for (int i = 2; i <= n; i++)
37+
{
38+
if ((d1[i - 1] + d2[i + 1]) > max)
39+
{
4140
max = d1[i - 1] + d2[i + 1];
4241
}
43-
if (d1[i] > max) {
42+
if (d1[i] > max)
43+
{
4444
max = d1[i];
4545
}
46+
if (d2[i] > max)
47+
{
48+
max = d2[i];
49+
}
4650
}
4751

4852
cout << max;

boj/17478/main.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
void writeDepth(int depth)
5+
{
6+
for (int i = 0; i < depth; i++)
7+
{
8+
cout << "____";
9+
}
10+
}
11+
12+
void recursive(int depth, int endCount)
13+
{
14+
writeDepth(depth);
15+
cout << "\"재귀함수가 뭔가요?\"\n";
16+
if (depth == endCount)
17+
{
18+
writeDepth(depth);
19+
cout << "\"재귀함수는 자기 자신을 호출하는 함수라네\"\n";
20+
}
21+
else
22+
{
23+
writeDepth(depth);
24+
cout << "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.\n";
25+
writeDepth(depth);
26+
cout << "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.\n";
27+
writeDepth(depth);
28+
cout << "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"\n";
29+
recursive(depth + 1, endCount);
30+
}
31+
writeDepth(depth);
32+
cout << "라고 답변하였지.\n";
33+
}
34+
35+
int main()
36+
{
37+
ios_base::sync_with_stdio(false);
38+
cout.tie(NULL);
39+
cin.tie(NULL);
40+
int n;
41+
cin >> n;
42+
43+
cout << "어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.\n";
44+
recursive(0, n);
45+
}

boj/1931/main.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
n = int(input())
1+
# n = int(input())
22

33

4-
pairs = []
4+
# pairs = []
55

6-
for _ in range(n):
7-
pairs.append(list(map(int, input().split())))
6+
# for _ in range(n):
7+
# pairs.append(list(map(int, input().split())))
88

9-
pairs.sort(key=lambda x: (x[1], x[0]))
9+
# pairs.sort(key=lambda x: (x[1], x[0]))
1010

11-
current = 0
12-
ans = 0
13-
for i in range(n):
14-
if pairs[i][0] >= current:
15-
current = pairs[i][1]
16-
ans += 1
11+
# current = 0
12+
# ans = 0
13+
# for i in range(n):
14+
# if pairs[i][0] >= current:
15+
# current = pairs[i][1]
16+
# ans += 1
1717

18-
print(ans)
18+
# print(ans)
1919

20+
21+
s = "blablablabl";
22+
23+
# s = "arosyutn";
24+
25+
s[0] = 'a';
26+
27+
s = "aaaaaaa"
28+
29+
s = "bbbbbbb"

boj/2146/main.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import queue
2+
import sys
3+
sys.setrecursionlimit(10**6)
4+
m = []
5+
6+
n = int(input())
7+
for _ in range(n):
8+
m.append(list(map(int, input().split())))
9+
10+
c = 20000
11+
12+
dx = [-1, 1, 0, 0]
13+
dy = [0, 0, -1, 1]
14+
15+
min_len = 10000
16+
17+
18+
def check(x, y):
19+
global m, c, n
20+
if x < 0 or y < 0 or x >= n or y >= n:
21+
return
22+
if m[x][y] == 1:
23+
m[x][y] = c
24+
for i in range(4):
25+
check(x + dx[i], y + dy[i])
26+
27+
28+
def bfs(sx, sy):
29+
global min_len
30+
q = queue.Queue(201)
31+
q.put([sx, sy])
32+
island = m[sx][sy]
33+
checker = [-1] * 10001
34+
checker[sx*n+sy] = 0
35+
m[sx][sy] = 0
36+
while not q.empty():
37+
[tx, ty] = q.get()
38+
if m[tx][ty] > 10000:
39+
continue
40+
41+
if min_len < checker[tx*n+ty]:
42+
continue
43+
44+
for i in range(4):
45+
x = tx + dx[i]
46+
y = ty + dy[i]
47+
if x < 0 or y < 0 or x >= n or y >= n:
48+
continue
49+
if m[x][y] != island and m[x][y] != 0:
50+
if min_len > checker[tx*n+ty]:
51+
min_len = checker[tx*n+ty]
52+
elif m[x][y] == 0 and checker[x*n+y] == -1:
53+
q.put([x, y])
54+
checker[x*n+y] = checker[tx*n+ty] + 1
55+
56+
m[sx][sy] = island
57+
58+
59+
def solve():
60+
global c
61+
for i in range(n):
62+
for j in range(n):
63+
if m[i][j] == 1:
64+
c += 1
65+
check(i, j)
66+
67+
for i in range(n):
68+
for j in range(n):
69+
if m[i][j]:
70+
bfs(i, j)
71+
72+
print(min_len)
73+
74+
75+
solve()

boj/2422/main.cpp

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
#include <iostream>
2-
#include <vector>
3-
#include <map>
4-
#include <tuple>
52
using namespace std;
63

4+
bool check[201][201];
5+
76
int main()
87
{
98
ios::sync_with_stdio(false);
109
cin.tie(NULL);
1110
cout.tie(NULL);
1211
int n, m;
1312
cin >> n >> m;
14-
map<tuple<int, int, int>, bool> tv;
15-
vector<pair<int, int>> vp;
16-
vp.reserve(m + 1);
13+
1714
for (int i = 1; i <= n; ++i)
1815
{
1916
for (int j = i + 1; j <= n; ++j)
2017
{
21-
for (int k = j + 1; k <= n; ++k)
22-
{
23-
tv[make_tuple(i, j, k)] = true;
24-
}
18+
check[i][j] = true;
19+
check[j][i] = true;
2520
}
2621
}
2722

@@ -30,39 +25,26 @@ int main()
3025
int i, j;
3126
cin >> i >> j;
3227

33-
vp.push_back(make_pair(i, j));
28+
check[i][j] = false;
29+
check[j][i] = false;
3430
}
35-
36-
auto it = tv.begin();
37-
38-
for (auto &p : vp)
31+
int ans = 0;
32+
for (int i = 1; i <= n; ++i)
3933
{
40-
for (it = tv.begin(); it != tv.end(); ++it)
34+
for (int j = i + 1; j <= n; ++j)
4135
{
42-
if (!it->second)
43-
{
44-
continue;
45-
}
46-
tuple<int, int, int> t = it->first;
47-
int f = get<0>(t);
48-
int s = get<1>(t);
49-
int th = get<2>(t);
50-
if (f == p.first || s == p.first || th == p.first)
36+
if (check[i][j] == true)
5137
{
52-
if (f == p.second || s == p.second || th == p.second)
38+
for (int k = j + 1; k <= n; ++k)
5339
{
54-
it->second = false;
40+
if (check[j][k] && check[i][k])
41+
{
42+
ans++;
43+
}
5544
}
5645
}
5746
}
5847
}
59-
int ans = 0;
60-
it = tv.begin();
61-
for (it = tv.begin(); it != tv.end(); ++it)
62-
{
63-
ans += it->second;
64-
}
65-
66-
cout << ans << endl;
48+
cout << ans << '\n';
6749
return 0;
6850
}

linked_list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Node:
2+
def __init__(self, data: int):
3+
self.data = data
4+
self.next = None
5+

0 commit comments

Comments
 (0)