Warning
This page is located in archive. Go to the latest version of this course pages.

This is an old revision of the document!


Cvičení 13

nadoby = list(map(int, input().split()))
x = int(input())

o=[[[0,0,0],'']]
c=[]
end = False

def konec(s):
    end = False
    for i in range(3):
        if s[0][i]==x:
            end = True
    return end

def stejny(a,b):
    return (a[0][0]==b[0][0]) and (a[0][1]==b[0][1]) and (a[0][2]==b[0][2]) 

def novy(s):
    ret = True
    for x in o:
        if stejny(s,x):
            ret = False
            break
    if ret:
      for x in c:
        if stejny(s,x):
            ret = False
            break
    return ret

while len(o)>0 and not end:
    s = o.pop(0)
    c.append(s)
    print('Stav',s)
    for i in range(3):
        s2 = [[s[0][0], s[0][1], s[0][2]],s[1]]
        s2[0][i]=nadoby[i]
        s2[1]+='N'+str(i)+'\n'
        if konec(s2):
            print(s2[1])
            end=True
            break
        if novy(s2):
            o.append(s2)
            print("Novy",s2)
            
    for i in range(3):
        s2 = [[s[0][0], s[0][1], s[0][2]],s[1]]
        s2[0][i]=0
        s2[1]+='V'+str(i)+'\n'
        if konec(s2):
            print(s2[1])
            end=True
            break
        if novy(s2):
            o.append(s2)
            print("Novy",s2)
    for i in range(3):
        if not end:
          for j in range(3):
            if (j!=i):
               s2 = [[s[0][0], s[0][1], s[0][2]],s[1]]
               if (s2[0][i]<=(nadoby[j]-s2[0][j])):
                   s2[0][j]+=s2[0][i]
                   s2[0][i]=0
               else:
                   s2[0][i]-=(nadoby[j]-s2[0][j])
                   s2[0][j]=nadoby[j]
               s2[1]+=str(i)+'P'+str(j)+'\n'
               if konec(s2):
                  print(s2[1])
                  end=True
                  break
               if novy(s2):
                  print("Novy",s2)
                  o.append(s2)
if not end:
    print("Nelze vyresit")

courses/b3b33alp/cviceni/t13.1578391893.txt.gz · Last modified: 2020/01/07 11:11 by stepan