예제 #1
0
  startValueX = data[start][xIndex]
  startValueY = data[start][yIndex]
  lastValueX = startValueX
  lastValueY = startValueY
  trendY = 0
  for row in range(start+1, len(data)):
    thisValueX = data[row][xIndex]
    thisValueY = data[row][yIndex]
    changeX = thisValueX - lastValueX
    changeY = thisValueY - lastValueY
    if(trendY == 0):
      trendY = changeY
    else:
      if(trendY < 0 and changeY > 0):
        return row
      elif(trendY > 0 and changeY < 0):
        return row
  return len(data) - 1
        


# Main program beings here
sys.setrecursionlimit(10000)
fileHandle = getInputFile('LHIP 240.txt')
fileHandle = findDataBeginningInFile(fileHandle)
allData = []
getValuesForQuanta(allData, fileHandle)
for d in allData:
  print d

예제 #2
0
from os import sys
sys.setrecursionlimit(50000)


def solve(pancake):
    #print "in\t\t",pancake

    top = 10
    while (pancake[top] == 0 and top >= 0):
        top -= 1

    if (top <= 3):
        return top

    pancake2 = dict(pancake)
    for i in range(1, 10):
        pancake2[i] = pancake2[i + 1]
    pancake2[10] = 0
    #print "eat\t\t",pancake2
    tmp = solve(dict(pancake2)) + 1

    for i in range(1, top):
        pancake3 = dict(pancake)
        pancake3[i] += pancake[top]
        pancake3[top - i] += pancake[top]
        pancake3[top] = 0
        #print "special," + str(i) + "\t",pancake3
        tmp = min(tmp, solve(dict(pancake3)) + pancake[top])
    return tmp

code_produit = [int(item) for item in input().split()]
plus_long = 0
arbre = {}

def trouver_produit(recherche, longueur=0):
    global recherches, arbre

    deja_trouve = True
    try:
        longueur_trouve = trouve[recherche]
    except:
        deja_trouve = False

    if recherche == 0:
        return longueur
    elif deja_trouve:
        return longueur + longueur_trouve
    else:
        nouvelle_longueur = trouver_produit(code_produit[recherche - 1], longueur+1)
        trouve[recherche] = nouvelle_longueur - longueur
        return nouvelle_longueur


sys.setrecursionlimit(len(code_produit))
for recherche in range(1, nbr_produit+1):
    nouvelle_longueur = trouver_produit(recherche)
    if nouvelle_longueur > plus_long:
        plus_long = nouvelle_longueur

print(plus_long)