ответ:я не уверена в ответах(давно не решала такие задачи)
16
[29, 31]
[28, 30]
12
[21, 23]
[20, 22]
Объяснение:
def moves(heap):
a,b=heap
return[(a+1,b),(2*a,b),(a,b+1),(a,b*2)]
table={(k,s):0 for k in range(501)for s in range(501)}
for x in table:
if any(sum(t)>=69 for t in moves(x)):
table[x]=1
if table[x]==0 and all(table[t]==1 for t in moves(x)):
table[x]=2
if table[x]==0 and any(table[t]==2 for t in moves(x)):
table[x]=3
if table[x]==0 and all(table[t]==3 or table[t]==1 for t in moves(x)):
table[x]=4
print(min([s for s in range(1,118)if any(table[t]==1 for t in moves((5,s)))]))
print([s for s in range(1,118)if table[(5,s)]==3])
print([s for s in range(1,118)if table[(5,s)]==4])
if any(sum(t)>=53 for t in moves(x)):
from itertools import product
i = open('input.txt', 'r')
o = open('output.txt', 'w+')
l = int(i.
alpha = "245"
d = []
for s in product(alpha, repeat=l):
d.append([" ".join(
for q in d[1: ]:
s = " ".join(q)
if int(s.count('2')) > 2:
continue
o.write(" ".join(q) + '\n')
i.close()
o.close()
код к : «перевод кода с питона на паскаль»
var
n,c,i,ost,b,t,d: integer;
a,k: string;
begin
readln(n);
c: =1;
for i: =1 to n do
c: =c*3;
c: =c-1;
for i: =1 to c do
k: ='';
b: =i;
t: =0;
while b> 0 do
ost: =b mod 3;
if ost=0 then inc(t);
d: =(-sqr(ost)+5*ost+4)div 2;
str(d,a);
k: =a+k;
b: =b div 3;
end;
while length(k)do
k: ='2'+k;
inc(t);
if t< =2 then writeln(k);
end.
ответ:я не уверена в ответах(давно не решала такие задачи)
16
[29, 31]
[28, 30]
12
[21, 23]
[20, 22]
Объяснение:
def moves(heap):
a,b=heap
return[(a+1,b),(2*a,b),(a,b+1),(a,b*2)]
table={(k,s):0 for k in range(501)for s in range(501)}
for x in table:
if any(sum(t)>=69 for t in moves(x)):
table[x]=1
for x in table:
if table[x]==0 and all(table[t]==1 for t in moves(x)):
table[x]=2
for x in table:
if table[x]==0 and any(table[t]==2 for t in moves(x)):
table[x]=3
for x in table:
if table[x]==0 and all(table[t]==3 or table[t]==1 for t in moves(x)):
table[x]=4
print(min([s for s in range(1,118)if any(table[t]==1 for t in moves((5,s)))]))
print([s for s in range(1,118)if table[(5,s)]==3])
print([s for s in range(1,118)if table[(5,s)]==4])
def moves(heap):
a,b=heap
return[(a+1,b),(2*a,b),(a,b+1),(a,b*2)]
table={(k,s):0 for k in range(501)for s in range(501)}
for x in table:
if any(sum(t)>=53 for t in moves(x)):
table[x]=1
for x in table:
if table[x]==0 and all(table[t]==1 for t in moves(x)):
table[x]=2
for x in table:
if table[x]==0 and any(table[t]==2 for t in moves(x)):
table[x]=3
for x in table:
if table[x]==0 and all(table[t]==3 or table[t]==1 for t in moves(x)):
table[x]=4
print(min([s for s in range(1,118)if any(table[t]==1 for t in moves((5,s)))]))
print([s for s in range(1,118)if table[(5,s)]==3])
print([s for s in range(1,118)if table[(5,s)]==4])
from itertools import product
i = open('input.txt', 'r')
o = open('output.txt', 'w+')
l = int(i.
alpha = "245"
d = []
for s in product(alpha, repeat=l):
d.append([" ".join(
for q in d[1: ]:
s = " ".join(q)
if int(s.count('2')) > 2:
continue
o.write(" ".join(q) + '\n')
i.close()
o.close()
код к : «перевод кода с питона на паскаль»
var
n,c,i,ost,b,t,d: integer;
a,k: string;
begin
readln(n);
c: =1;
for i: =1 to n do
c: =c*3;
c: =c-1;
for i: =1 to c do
begin
k: ='';
b: =i;
t: =0;
while b> 0 do
begin
ost: =b mod 3;
if ost=0 then inc(t);
d: =(-sqr(ost)+5*ost+4)div 2;
str(d,a);
k: =a+k;
b: =b div 3;
end;
while length(k)do
begin
k: ='2'+k;
inc(t);
end;
if t< =2 then writeln(k);
end;
end.