Merge remote-tracking branch 'origin/master'
This commit is contained in:
22
zeta_cpp/completed/14215.cpp
Normal file
22
zeta_cpp/completed/14215.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int sides[3];
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
cin >> sides[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(sides, sides + 3);
|
||||||
|
|
||||||
|
if (sides[2] >= sides[1] + sides[0]) {
|
||||||
|
sides[2] = sides[1] + sides[0] - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << accumulate(sides, sides + 3, 0) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
14
zeta_cpp/completed/15894.cpp
Normal file
14
zeta_cpp/completed/15894.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
long long solve(long long n) {
|
||||||
|
return 4 * n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
long long n;
|
||||||
|
cin >> n;
|
||||||
|
cout << solve(n);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
10
zeta_cpp/completed/27323.cpp
Normal file
10
zeta_cpp/completed/27323.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int A, B;
|
||||||
|
cin >> A >> B;
|
||||||
|
cout << A * B;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
35
zeta_cpp/completed/5073.cpp
Normal file
35
zeta_cpp/completed/5073.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int sides[3];
|
||||||
|
while (true) {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
cin >> sides[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sides[0] == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sort(sides, sides + 3);
|
||||||
|
|
||||||
|
if (sides[0] + sides[1] <= sides[2]) {
|
||||||
|
cout << "Invalid\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sides[0] == sides[1] and sides[1] == sides[2] and sides[2] == sides[0]) {
|
||||||
|
cout << "Equilateral\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (sides[0] == sides[1] or sides[0] == sides[2] or sides[1] == sides[2]) {
|
||||||
|
cout << "Isosceles\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Scalene\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
20
zeta_cpp/completed/9063.cpp
Normal file
20
zeta_cpp/completed/9063.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N;
|
||||||
|
cin >> N;
|
||||||
|
int xs[N], ys[N];
|
||||||
|
int x, y;
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
cin >> x >> y;
|
||||||
|
xs[i] = x;
|
||||||
|
ys[i] = y;
|
||||||
|
}
|
||||||
|
sort(xs, xs + N);
|
||||||
|
sort(ys, ys + N);
|
||||||
|
|
||||||
|
cout << (xs[N - 1] - xs[0]) * (ys[N - 1] - ys[0]) << endl;
|
||||||
|
}
|
||||||
0
zeta_python/5427.py
Normal file
0
zeta_python/5427.py
Normal file
45
zeta_python/completed/1260.py
Normal file
45
zeta_python/completed/1260.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
def dfs(N, M, E, V):
|
||||||
|
D = []
|
||||||
|
D.append((V))
|
||||||
|
visited = []
|
||||||
|
while D:
|
||||||
|
now = D.pop()
|
||||||
|
if now in visited:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
visited.append(now)
|
||||||
|
for i in E[now][::-1]:
|
||||||
|
D.append(i)
|
||||||
|
|
||||||
|
return visited
|
||||||
|
|
||||||
|
|
||||||
|
def bfs(N, M, E, V):
|
||||||
|
D = []
|
||||||
|
D.append((V))
|
||||||
|
visited = []
|
||||||
|
while D:
|
||||||
|
now = D.pop(0)
|
||||||
|
if now in visited:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
visited.append(now)
|
||||||
|
for i in E[now]:
|
||||||
|
D.append(i)
|
||||||
|
|
||||||
|
return visited
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
N, M, V = map(int, input().split())
|
||||||
|
E = {}
|
||||||
|
for i in range(1, N + 1):
|
||||||
|
E[i] = []
|
||||||
|
for i in range(1, M + 1):
|
||||||
|
a, b = map(int, input().split())
|
||||||
|
E[a].append(b)
|
||||||
|
E[b].append(a)
|
||||||
|
for i in range(1, N + 1):
|
||||||
|
E[i].sort()
|
||||||
|
print(*dfs(N, M, E, V))
|
||||||
|
print(*bfs(N, M, E, V))
|
||||||
28
zeta_python/completed/1389.py
Normal file
28
zeta_python/completed/1389.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
def get_kevin(N, p, E):
|
||||||
|
D = []
|
||||||
|
D.append((p, 0))
|
||||||
|
kevins = [-1 for _ in range(N + 1)]
|
||||||
|
while D:
|
||||||
|
now, cost = D.pop(0)
|
||||||
|
if kevins[now] == -1:
|
||||||
|
kevins[now] = cost
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for arrow in E[now]:
|
||||||
|
D.append((arrow, cost + 1))
|
||||||
|
return sum(kevins)
|
||||||
|
|
||||||
|
|
||||||
|
def get_lowest_kevin(N, E):
|
||||||
|
return min([(get_kevin(N, i, E), i) for i in range(1, N + 1)])[1]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
E = [[] for _ in range(N + 1)]
|
||||||
|
for _ in range(M):
|
||||||
|
i, j = map(int, input().split())
|
||||||
|
E[i].append(j)
|
||||||
|
E[j].append(i)
|
||||||
|
print(get_lowest_kevin(N, E))
|
||||||
36
zeta_python/completed/14940.py
Normal file
36
zeta_python/completed/14940.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
def solve(N, M, X, dest):
|
||||||
|
delta = ((-1, 0), (1, 0), (0, 1), (0, -1))
|
||||||
|
D = []
|
||||||
|
# X = [[-1] * M for _ in range(N)]
|
||||||
|
|
||||||
|
D.append((dest, 0))
|
||||||
|
while D:
|
||||||
|
now, cost = D.pop(0)
|
||||||
|
if X[now[0]][now[1]] == -1:
|
||||||
|
X[now[0]][now[1]] = cost
|
||||||
|
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for dx, dy in delta:
|
||||||
|
new = now[0] + dx, now[1] + dy
|
||||||
|
if 0 <= new[0] < N and 0 <= new[1] < M:
|
||||||
|
D.append((new, cost + 1))
|
||||||
|
return X
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
U = []
|
||||||
|
X = [[-1] * M for _ in range(N)]
|
||||||
|
dest: tuple
|
||||||
|
for i in range(N):
|
||||||
|
temp = list(map(int, input().split()))
|
||||||
|
for j, v in enumerate(temp):
|
||||||
|
if v == 0:
|
||||||
|
X[i][j] = 0
|
||||||
|
elif v == 2:
|
||||||
|
dest = (i, j)
|
||||||
|
|
||||||
|
for i in solve(N, M, X, dest):
|
||||||
|
print(*i)
|
||||||
33
zeta_python/completed/1697.py
Normal file
33
zeta_python/completed/1697.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
from queue import Queue
|
||||||
|
|
||||||
|
|
||||||
|
def solve(N, K):
|
||||||
|
D = Queue()
|
||||||
|
M = [0] * 100001
|
||||||
|
D.put((N, 0))
|
||||||
|
while D:
|
||||||
|
now, t = D.get()
|
||||||
|
if now > 100000 or now < 0:
|
||||||
|
continue
|
||||||
|
if M[now] == 0:
|
||||||
|
M[now] = t
|
||||||
|
elif t > M[now]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
target = []
|
||||||
|
|
||||||
|
if now > K:
|
||||||
|
target.append((now - 1, t + 1))
|
||||||
|
elif now == K:
|
||||||
|
return t
|
||||||
|
elif now < K:
|
||||||
|
target.append((2 * now, t + 1))
|
||||||
|
target.append((now + 1, t + 1))
|
||||||
|
target.append((now - 1, t + 1))
|
||||||
|
for temp in target:
|
||||||
|
D.put(temp)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
N, K = map(int, input().split())
|
||||||
|
print(solve(N, K))
|
||||||
44
zeta_python/completed/7569.py
Normal file
44
zeta_python/completed/7569.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
def check(U):
|
||||||
|
for i in U:
|
||||||
|
for j in i:
|
||||||
|
for k in j:
|
||||||
|
if k == 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def solve(M, N, H, U, ir):
|
||||||
|
step = 0
|
||||||
|
delta = ((-1, 0, 0), (1, 0, 0), (0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1))
|
||||||
|
rotten = [ir]
|
||||||
|
while not check(U):
|
||||||
|
rotten.append([])
|
||||||
|
for r in rotten[step]:
|
||||||
|
for dm, dn, dh in delta:
|
||||||
|
new = r[0] + dm, r[1] + dn, r[2] + dh
|
||||||
|
if 0 <= new[0] < M and 0 <= new[1] < N and 0 <= new[2] < H:
|
||||||
|
if U[new[2]][new[1]][new[0]] != 0:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
U[new[2]][new[1]][new[0]] = 1
|
||||||
|
rotten[step + 1].append(new)
|
||||||
|
if rotten[-1]:
|
||||||
|
step += 1
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
return step
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
M, N, H = map(int, input().split())
|
||||||
|
U = [[[None for _ in range(M)] for _ in range(N)] for _ in range(H)] # U[h][n][m]
|
||||||
|
init_rottens = []
|
||||||
|
for h in range(H):
|
||||||
|
for n in range(N):
|
||||||
|
for m, v in enumerate(map(int, input().split())):
|
||||||
|
U[h][n][m] = v
|
||||||
|
if v == 1:
|
||||||
|
init_rottens.append((m, n, h))
|
||||||
|
|
||||||
|
print(solve(M, N, H, U, init_rottens))
|
||||||
Reference in New Issue
Block a user