This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertionSort(At, Nt): | |
for i in range(Nt): | |
v = At[i] | |
j = i - 1 | |
while j >= 0 and At[j] > v: | |
A[j + 1] = A[j] | |
j = j - 1 | |
A[j + 1] = v | |
print(" ".join(map(str,At))) | |
return At |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd(a, b): | |
if a < b: | |
tmp = a | |
a = b | |
b = tmp | |
r = a % b | |
while r != 0: | |
a = b | |
b = r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# endを指定しない場合は,"\n"がデフォルト.最後に改行が行われる | |
print("hoge") | |
# endに空文字を指定すると,改行されない | |
print("hoge", end="") | |
# print()関数の引数は,複数に対応している.sepを指定しない場合,デフォルトでは結合文字は半角スペース. | |
print("foo", "bar") | |
#sepを指定することで,結合文字を変更することができる |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def sieve(x): | |
prime = [True for i in range(x)] | |
for i in range(2, int(math.sqrt(x))): | |
if prime[i] == True: | |
j = 0 | |
while i * (j + 2) < x: | |
prime[i * (j + 2)] = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
n = int(input()) | |
R = [int(input()) for i in range(n)] | |
minv = R[0] | |
maxv = R[1] - R[0] | |
for j in range(1, n): | |
if (maxv < R[j] - minv): | |
maxv = R[j] - minv | |
if (R[j] < minv): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bubbleSort(R, N): | |
flag = True | |
cnt = 0 | |
while flag == True: | |
flag = False | |
for j in range(N - 1, 0, -1): | |
if R[j] < R[j - 1]: | |
tmp = R[j] | |
R[j] = R[j - 1] | |
R[j - 1] = tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selectionSort(A, N): | |
global cnt | |
for i in range(N): | |
minj = i | |
for j in range(i, N): | |
if A[j] < A[minj]: | |
minj = j | |
if i != minj: | |
tmp = A[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selectionSort(A, N): | |
for i in range(N): | |
minj = i | |
for j in range(i, N): | |
if A[j][1:] < A[minj][1:]: | |
minj = j | |
if i != minj: | |
tmp = A[i] | |
A[i] = A[minj] | |
A[minj] = tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertionSort(A, n, g): | |
global cnt | |
for i in range(g, n): | |
v = A[i] | |
j = i - g | |
while j >= 0 and A[j] > v: | |
A[j + g] = A[j] | |
j = j - g | |
cnt = cnt + 1 |
OlderNewer