Example #1
0
    while secondv_j < end:
        # xより小さい場合の処理.大きい場合はjを進めるだけ.
        if v[secondv_j] <= endval:
            firstv_i += 1
            v[firstv_i], v[secondv_j] = v[secondv_j], v[firstv_i]
        secondv_j += 1
    v[firstv_i + 1], v[end] = v[end], v[firstv_i + 1]
    print(v)
    return firstv_i + 1


test_listOne = [3, 2, 4, 1]
test_listTwo = [10, 8, 4, 19, 2, 20, 5]
test_listThree = list(range(1, 101))
test_listFour = list(
    map(int, ImportCase.autoinput_returnlist("ALDS1_1Short.txt")))
test_listFive = [4, 8, 9, 1, 10, 6, 2, 5, 3, 7]
test_listSix = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
# 1000行のデータ:
# 挿入ソート:0.31秒.
# バブルソート:0.45秒
# 選択ソート:0.44秒
# マージソート:0.012秒

#start_time = time.time()
#mergesort(test_listFour, 0, len(test_listFour))
#print(test_listFour)
#print(time.time() - start_time)

print(partition(test_listSix, 0, len(test_listSix) - 1))
Example #2
0
    minv = test_list[1]
    maxv = -10000000000
    for x in test_list[2:]:
        tmp_max = x - minv
        if tmp_max > maxv:
            maxv = tmp_max
        if x < minv:
            minv = x
    print(maxv)


testOne = [6, 5, 3, 1, 3, 4, 3]
testTwo = [3, 4, 3, 2]
testThree = [7, 3, 2, 4, 1, 5, 3, 6]
testFour = [2, 100000, 1]
testFive = list(map(int, ImportCase.autoinput_returnlist("ALDS1_1Short.txt")))

# Algorithms1での実行 O(n^2)
start_time = time.time()
output_max_One(testOne)
output_max_One(testTwo)
output_max_One(testThree)
output_max_One(testFour)
output_max_One(testFive)
print(time.time() - start_time)

# Algorithm2での実行 O(n)
start_time = time.time()
output_max_Two(testOne)
output_max_Two(testTwo)
output_max_Two(testThree)
Example #3
0
# coding: utf-8

# inputの代わり(テストコード)
from paiza import ImportCase

p = ImportCase.auto_input("amidatest.txt")

# initialize the vector of amidakuji
input_lines = p.__next__()
input_lines = list(map(int, input_lines.split(" ")))

amida_list = [["0" for i in range(input_lines[0] + 1)]
              for j in range(input_lines[1])]
lengthOfline = input_lines[0]
numOfvline = input_lines[1]
numOfhline = input_lines[2]

# あみだくじ作成
for i in range(numOfhline):
    input_lines = p.__next__()
    input_lines = list(map(int, input_lines.split(" ")))
    row = input_lines[0] - 1
    col = input_lines[1]
    val = input_lines[2]
    amida_list[row][col] = val
    amida_list[row + 1][val] = -col

# search for the answer
for p in range(numOfvline):
    row_p = p
    col_p = 1
Example #4
0
from paiza import ImportCase
from collections import OrderedDict

p = ImportCase.auto_input("PlanWeather.txt")


def arrange_line(line):
    return list(map(int, line.split(" ")))


input_lines = arrange_line(p.__next__())
numHoliday = input_lines[0]
numTrip = input_lines[1]
ProbDict = OrderedDict()
numloop = numHoliday - numTrip + 1

for i in range(numHoliday):
    input_lines = arrange_line(p.__next__())
    ProbDict[input_lines[0]] = input_lines[1]

Prob_i = min(ProbDict.keys())
ans = Prob_i
max_sum = numTrip * 100

for i in range(numloop):
    Prosum = 0
    for ii in range(Prob_i, Prob_i + numTrip):
        Prosum += ProbDict[ii]
    if max_sum > Prosum:
        max_sum = Prosum
        ans = Prob_i
Example #5
0
# とりあえずクラスを用いて実装すべきでした。

# inputの代わり(テストコード)
from paiza import ImportCase
p = ImportCase.auto_input("otimono2.txt")
input_lines = p.__next__()
input_lines = list(map(int, input_lines.split(" ")))


fields = []
for y in range(input_lines[0]):
    fields.append(["." for x in range(input_lines[1])])

numRow = input_lines[0]
numCol = input_lines[1]
numLoop = input_lines[2]


def searchRow(StartPos, Putpos):
    # 行の走査
    while StartPos < numRow - 1:
        if fields[StartPos][putPos] == "#":
            StartPos -= 1
            break
        StartPos += 1

    for x in range(colPos):
        if fields[StartPos][putPos + x] == "#":
            searchRow(StartPos)
    return StartPos
Example #6
0
# coding: utf-8

# inputの代わり(テストコード)
from paiza import ImportCase
p = ImportCase.auto_input("amidatest.txt")


# initialize the vector of amidakuji
input_lines = p.__next__()
input_lines = list(map(int, input_lines.split(" ")))

amida_list = [["0" for i in range(input_lines[0]+1)] for j in range(input_lines[1])]
lengthOfline = input_lines[0]
numOfvline = input_lines[1]
numOfhline = input_lines[2]


# あみだくじ作成
for i in range(numOfhline):
    input_lines = p.__next__()
    input_lines = list(map(int, input_lines.split(" ")))
    row = input_lines[0] - 1
    col = input_lines[1]
    val = input_lines[2]
    amida_list[row][col] = val
    amida_list[row+1][val] = -col

# search for the answer
for p in range(numOfvline):
    row_p = p
    col_p = 1
Example #7
0
from paiza import ImportCase
from collections import OrderedDict

p = ImportCase.auto_input("PlanWeather.txt")


def arrange_line(line):
    return list(map(int, line.split(" ")))


input_lines = arrange_line(p.__next__())
numHoliday = input_lines[0]
numTrip = input_lines[1]
ProbDict = OrderedDict()
numloop = numHoliday - numTrip + 1

for i in range(numHoliday):
    input_lines = arrange_line(p.__next__())
    ProbDict[input_lines[0]] = input_lines[1]

Prob_i = min(ProbDict.keys())
ans = Prob_i
max_sum = numTrip * 100

for i in range(numloop):
    Prosum = 0
    for ii in range(Prob_i, Prob_i + numTrip):
        Prosum += ProbDict[ii]
    if max_sum > Prosum:
        max_sum = Prosum
        ans = Prob_i