boj step 9 rework & aloha graph1(16174,2606,1520)
This commit is contained in:
29
zeta_cpp/completed/2501.cpp
Normal file
29
zeta_cpp/completed/2501.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int count = 1;
|
||||
int N, K;
|
||||
|
||||
cin >> N >> K;
|
||||
if(K == 1) {
|
||||
cout << 1 << endl;
|
||||
return 0;
|
||||
}
|
||||
for(int i=2;i<=N;i++) {
|
||||
if (N%i == 0) {
|
||||
count += 1;
|
||||
if (count == K) {
|
||||
cout << i << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (K > count) {
|
||||
cout << 0 << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
45
zeta_cpp/completed/9506.cpp
Normal file
45
zeta_cpp/completed/9506.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> isPerfect(int N) {
|
||||
vector<int> v;
|
||||
for (int i = 1; i < N; i++) {
|
||||
if (N % i == 0) {
|
||||
v.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
int result = accumulate(v.begin(), v.end(), 0);
|
||||
if (result == N) {
|
||||
return v;
|
||||
} else {
|
||||
return vector<int>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int input;
|
||||
vector<int> out;
|
||||
cin >> input;
|
||||
while (input != -1) {
|
||||
|
||||
out = isPerfect(input);
|
||||
if (out.size() > 0) {
|
||||
cout << input << " = " << out[0];
|
||||
for (int i = 1; i < out.size(); i++) {
|
||||
cout << " + " << out[i];
|
||||
}
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << input << " is NOT perfect." << endl;
|
||||
}
|
||||
cin >> input;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
0
zeta_python/1967.py
Normal file
0
zeta_python/1967.py
Normal file
4
zeta_python/completed/1271.py
Normal file
4
zeta_python/completed/1271.py
Normal file
@@ -0,0 +1,4 @@
|
||||
a, b = map(int, input().split())
|
||||
|
||||
print(a // b)
|
||||
print(a % b)
|
||||
32
zeta_python/completed/1520.py
Normal file
32
zeta_python/completed/1520.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import sys
|
||||
|
||||
sys.setrecursionlimit(1 << 16)
|
||||
|
||||
|
||||
def solve(M, N, U):
|
||||
"""get count of pathes"""
|
||||
|
||||
Mem = [[-1 for _ in range(N)] for _ in range(M)]
|
||||
Mem[M - 1][N - 1] = 1
|
||||
|
||||
def dfs(now):
|
||||
x, y = now
|
||||
if Mem[x][y] != -1:
|
||||
return Mem[x][y]
|
||||
cnt = 0
|
||||
for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
_x, _y = x + i, y + j
|
||||
if 0 <= _x < M and 0 <= _y < N and U[_x][_y] < U[x][y]:
|
||||
cnt += dfs((_x, _y))
|
||||
|
||||
Mem[x][y] = cnt
|
||||
return Mem[x][y]
|
||||
|
||||
dfs((0, 0))
|
||||
return Mem[0][0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
M, N = map(int, input().split())
|
||||
U = [list(map(int, input().split())) for _ in range(M)] # U[m][n]
|
||||
print(solve(M, N, U))
|
||||
33
zeta_python/completed/16174.py
Normal file
33
zeta_python/completed/16174.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def solve(N, A) -> bool:
|
||||
now = (0, 0)
|
||||
D = []
|
||||
D.append(now)
|
||||
X = [[0 for _ in range(N)]for _ in range(N)]
|
||||
while D:
|
||||
now = D.pop()
|
||||
amount = A[now[0]][now[1]]
|
||||
if X[now[0]][now[1]]:
|
||||
continue
|
||||
X[now[0]][now[1]] = 1
|
||||
if amount == 0:
|
||||
continue
|
||||
elif amount == -1:
|
||||
return True
|
||||
if now[0] + amount >= N:
|
||||
pass
|
||||
else:
|
||||
target = (now[0] + amount, now[1])
|
||||
D.append(target)
|
||||
if now[1] + amount >= N:
|
||||
pass
|
||||
else:
|
||||
target = (now[0], now[1] + amount)
|
||||
D.append(target)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N = int(input())
|
||||
A = [list(map(int, input().split())) for _ in range(N)]
|
||||
print("HaruHaru" if solve(N, A) else "Hing")
|
||||
30
zeta_python/completed/2606.py
Normal file
30
zeta_python/completed/2606.py
Normal file
@@ -0,0 +1,30 @@
|
||||
def solve(N, X, E):
|
||||
ComputerMap = {}
|
||||
WormMap = [0 for i in range(N + 1)]
|
||||
WormMap[1] = 1
|
||||
for i in range(1, N + 1):
|
||||
ComputerMap[i] = []
|
||||
for e in E:
|
||||
ComputerMap[e[0]].append(e[1])
|
||||
ComputerMap[e[1]].append(e[0])
|
||||
|
||||
D = []
|
||||
D.append(1)
|
||||
while D:
|
||||
x = D.pop()
|
||||
connected = ComputerMap[x]
|
||||
for conn in connected:
|
||||
if WormMap[conn]:
|
||||
continue
|
||||
else:
|
||||
WormMap[conn] = 1
|
||||
D.append(conn)
|
||||
|
||||
return sum(WormMap) - 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N = int(input())
|
||||
X = int(input())
|
||||
E = list(sorted(list(map(int, input().split()))) for _ in range(X))
|
||||
print(solve(N, X, E))
|
||||
Reference in New Issue
Block a user