n, m = [int(_) for _ in input("Zadaj rozmery n, m: ").split()]
budova = [['.' for s in range(n)] for r in range(n)]
for _ in range(m):
r, s = [int(_) for _ in input("Zadaj poziciu r, s: ").split()]
assert 0 < r <= n and 0 < s <= n, "Nespravna pozicia"
budova[r-1][s-1] = '*'
Zadaj rozmery n, m: 2 3 Zadaj poziciu r, s: 1 1 Zadaj poziciu r, s: 1 2 Zadaj poziciu r, s: 2 2
budova
[['*', '*'], ['.', '*']]
for riadok in budova:
print(riadok)
['*', '*'] ['.', '*']
for riadok in budova:
print(*riadok)
* * . *
import pandas as pd
def zobraz(data):
df = pd.DataFrame(data)
df = df.style.applymap(lambda val: f'color: {"green" if val in ["*"] else "blue" if val == "." else "red" }')
return df
zobraz(budova)
Matplotlib is building the font cache; this may take a moment.
0 | 1 | |
---|---|---|
0 | * | * |
1 | . | * |
n, m = [int(_) for _ in input("Zadaj rozmery n, m: ").split()]
budova = [['.' for s in range(n)] for r in range(n)]
for _ in range(m):
r, s = [int(_) for _ in input("Zadaj poziciu r, s: ").split()]
assert 0 < r <= n and 0 < s <= n, "Nespravna pozicia"
budova[r-1][s-1] = '*'
Zadaj rozmery n, m: 3 3 Zadaj poziciu r, s: 3 3 Zadaj poziciu r, s: 1 1 Zadaj poziciu r, s: 2 1
zobraz(budova)
0 | 1 | 2 | |
---|---|---|---|
0 | * | . | . |
1 | * | . | . |
2 | . | . | * |
budova[1][0] = '+'
zobraz(budova)
0 | 1 | 2 | |
---|---|---|---|
0 | * | . | . |
1 | + | . | . |
2 | . | . | * |
budova[1][1] = '+'
budova[1][2] = '+'
zobraz(budova)
0 | 1 | 2 | |
---|---|---|---|
0 | * | . | . |
1 | + | + | + |
2 | . | . | * |
n, m = [int(_) for _ in input("Zadaj rozmery n, m: ").split()]
budova = [['.' for s in range(n)] for r in range(n)]
for _ in range(m):
r, s = [int(_) for _ in input("Zadaj poziciu r, s: ").split()]
assert 0 < r <= n and 0 < s <= n, "Nespravna pozicia"
budova[r-1][s-1] = '*'
Zadaj rozmery n, m: 3 3 Zadaj poziciu r, s: 3 3 Zadaj poziciu r, s: 1 1 Zadaj poziciu r, s: 2 2
zobraz(budova)
0 | 1 | 2 | |
---|---|---|---|
0 | * | . | . |
1 | . | * | . |
2 | . | . | * |
n, m = [int(_) for _ in input("Zadaj rozmery n, m: ").split()]
budova = [['.' for s in range(n)] for r in range(n)]
for _ in range(m):
r, s = [int(_) for _ in input("Zadaj poziciu r, s: ").split()]
assert 0 < r <= n and 0 < s <= n, "Nespravna pozicia"
budova[r-1][s-1] = '*'
zobraz(budova)
Zadaj rozmery n, m: 3 3 Zadaj poziciu r, s: 3 3 Zadaj poziciu r, s: 1 1 Zadaj poziciu r, s: 1 2
0 | 1 | 2 | |
---|---|---|---|
0 | * | * | . |
1 | . | . | . |
2 | . | . | * |
print(-1)
-1
!type nacitaj.py
n, m = [int(_) for _ in input("Zadaj rozmery n, m: ").split()] budova = [['.' for s in range(n)] for r in range(n)] for _ in range(m): r, s = [int(_) for _ in input("Zadaj poziciu r, s: ").split()] assert 0 < r <= n and 0 < s <= n, "Nespravna pozicia" budova[r-1][s-1] = '*' for riadok in budova: print(*riadok)
!type vstup.txt
2 3 1 1 1 2 2 2
!python nacitaj.py <vstup.txt >vystup.txt
!type vystup.txt
Zadaj rozmery n, m: Zadaj poziciu r, s: Zadaj poziciu r, s: Zadaj poziciu r, s: * * . *
from math import factorial, pi, cos, sin
import matplotlib.pyplot as plt
from itertools import permutations
n = 3
hrany = [(0,1), (0,2)]
sx, sy, r = 0.5, 0.5, 0.4
count = factorial(n)
fig, ax = plt.subplots(figsize=(20, 20*count//24))
index = 1
def bod(x, radius=r):
uhol = x*2*pi/n+pi/2
return (sx+radius*cos(uhol), sy+radius*sin(uhol))
def check_perm(perm):
for pair in permutations(hrany, 2):
a, b = sorted([perm[pair[0][0]], perm[pair[0][1]]])
c, d = [perm[pair[1][0]], perm[pair[1][1]]]
if c == a or c == b or d == a or d == b:
continue
if (a < c < b+1) ^ (a < d < b+1):
return False
return True
for perm in permutations(range(n)):
# print(perm)
sp = fig.add_subplot((count+5)//6, 6, index)
# sp.text(0.5, 0.5, str(index), fontsize=12)
index += 1
circle1 = plt.Circle((sx, sy), r, color='g' if check_perm(perm) else 'r', fill=False, lw=4)
sp.add_patch(circle1)
sp.axis('off')
sp.set_aspect(1.0)
for x in range(n):
sp.add_patch(plt.Circle(bod(x), 0.01, color='b', fill=True, lw=10))
tx, ty = bod(x, 0.5)
sp.text(tx, ty, str(perm[x]), fontsize=12, ha='center', va = 'center')
for i, j in hrany:
bi, bj = bod(perm[i]), bod(perm[j])
lx, ly = (bi[0], bj[0]), (bi[1], bj[1])
sp.add_line(plt.Line2D(lx, ly, color='k', lw=3))
ax.axis('off')
(0.0, 1.0, 0.0, 1.0)
from math import factorial
n = 4
hrany = [(0,1), (1, 2), (2, 3)]
sx, sy, r = 0.5, 0.5, 0.4
count = factorial(n)
fig, ax = plt.subplots(figsize=(20, 20*count//24))
index = 1
def bod(x, radius=r):
uhol = x*2*pi/n+pi/2
return (sx+radius*cos(uhol), sy+radius*sin(uhol))
for perm in permutations(range(n)):
# print(perm)
sp = fig.add_subplot((count+5)//6, 6, index)
# sp.text(0.5, 0.5, str(index), fontsize=12)
index += 1
circle1 = plt.Circle((sx, sy), r, color='g' if check_perm(perm) else 'r', fill=False, lw=4)
sp.add_patch(circle1)
sp.axis('off')
sp.set_aspect(1.0)
for x in range(n):
sp.add_patch(plt.Circle(bod(x), 0.01, color='b', fill=True, lw=10))
tx, ty = bod(x, 0.5)
sp.text(tx, ty, str(perm[x]), fontsize=12, ha='center', va = 'center')
for i, j in hrany:
bi, bj = bod(perm[i]), bod(perm[j])
lx, ly = (bi[0], bj[0]), (bi[1], bj[1])
sp.add_line(plt.Line2D(lx, ly, color='k', lw=3))
ax.axis('off')
(0.0, 1.0, 0.0, 1.0)
list(permutations('ABC'))
[('A', 'B', 'C'), ('A', 'C', 'B'), ('B', 'A', 'C'), ('B', 'C', 'A'), ('C', 'A', 'B'), ('C', 'B', 'A')]
post = [1,1,1,5,1,1,1]
index = 0
while post[index] < 2:
index += 1
print(index)
3
x = post[index]
post[:index]+[x//2, x%2, x//2]+post[index+1:]
[1, 1, 1, 2, 1, 2, 1, 1, 1]
post = [5]
while max(post) > 1:
index = 0
while post[index] < 2:
index += 1
x = post[index]
post = post[:index]+[x//2, x%2, x//2]+post[index+1:]
print(post)
[2, 1, 2] [1, 0, 1, 1, 2] [1, 0, 1, 1, 1, 0, 1]
V úseku 2-4 (011) sú dve jednotky, výstup 2
post = [6]
while max(post) > 1:
index = 0
while post[index] < 2:
index += 1
x = post[index]
post = post[:index]+[x//2, x%2, x//2]+post[index+1:]
print(post)
[3, 0, 3] [1, 1, 1, 0, 3] [1, 1, 1, 0, 1, 1, 1]
post = [7]
while max(post) > 1:
index = 0
while post[index] < 2:
index += 1
x = post[index]
post = post[:index]+[x//2, x%2, x//2]+post[index+1:]
print(post)
[3, 1, 3] [1, 1, 1, 1, 3] [1, 1, 1, 1, 1, 1, 1]
from itertools import product
for perm in product('0123', repeat=2):
print(perm)
('0', '0') ('0', '1') ('0', '2') ('0', '3') ('1', '0') ('1', '1') ('1', '2') ('1', '3') ('2', '0') ('2', '1') ('2', '2') ('2', '3') ('3', '0') ('3', '1') ('3', '2') ('3', '3')
from graphviz import Graph
g = Graph()
g.edge('1', '2')
g
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_10492\2981092879.py in <module> ----> 1 from graphviz import Graph 2 3 g = Graph() 4 g.edge('1', '2') 5 g ModuleNotFoundError: No module named 'graphviz'
!pip install graphviz
Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: graphviz in c:\users\hp\appdata\roaming\python\python39\site-packages (0.20.1)
data = []
for perm in product('0123', repeat=2):
data.append([f'{int(i):02b} ({i})' for i in perm]+['NIE' if perm[0] == '0' or perm[0] == perm[1] else 'MOZNO',
'NIE' if perm[1] == '0' or perm[0] == perm[1] else 'MOZNO',
'NIE' if perm[0] == '0' or perm[0] == perm[1] or perm[1] == '0' else 'ANO',
])
data
[['00 (0)', '00 (0)', 'NIE', 'NIE', 'NIE'], ['00 (0)', '01 (1)', 'NIE', 'MOZNO', 'NIE'], ['00 (0)', '10 (2)', 'NIE', 'MOZNO', 'NIE'], ['00 (0)', '11 (3)', 'NIE', 'MOZNO', 'NIE'], ['01 (1)', '00 (0)', 'MOZNO', 'NIE', 'NIE'], ['01 (1)', '01 (1)', 'NIE', 'NIE', 'NIE'], ['01 (1)', '10 (2)', 'MOZNO', 'MOZNO', 'ANO'], ['01 (1)', '11 (3)', 'MOZNO', 'MOZNO', 'ANO'], ['10 (2)', '00 (0)', 'MOZNO', 'NIE', 'NIE'], ['10 (2)', '01 (1)', 'MOZNO', 'MOZNO', 'ANO'], ['10 (2)', '10 (2)', 'NIE', 'NIE', 'NIE'], ['10 (2)', '11 (3)', 'MOZNO', 'MOZNO', 'ANO'], ['11 (3)', '00 (0)', 'MOZNO', 'NIE', 'NIE'], ['11 (3)', '01 (1)', 'MOZNO', 'MOZNO', 'ANO'], ['11 (3)', '10 (2)', 'MOZNO', 'MOZNO', 'ANO'], ['11 (3)', '11 (3)', 'NIE', 'NIE', 'NIE']]
import pandas as pd
def zobraz(data):
df = pd.DataFrame(data, columns=['Vestec1', 'Vestec2', 'Vysledok1', 'Vysledok2', 'Celkovo'])
df = df.style.applymap(lambda val: f'color: {"green" if val in ["ANO"] else "red" if val == "NIE" else "black" if val == "MOZNO" else "blue" }')
return df
zobraz(data)
Vestec1 | Vestec2 | Vysledok1 | Vysledok2 | Celkovo | |
---|---|---|---|---|---|
0 | 00 (0) | 00 (0) | NIE | NIE | NIE |
1 | 00 (0) | 01 (1) | NIE | MOZNO | NIE |
2 | 00 (0) | 10 (2) | NIE | MOZNO | NIE |
3 | 00 (0) | 11 (3) | NIE | MOZNO | NIE |
4 | 01 (1) | 00 (0) | MOZNO | NIE | NIE |
5 | 01 (1) | 01 (1) | NIE | NIE | NIE |
6 | 01 (1) | 10 (2) | MOZNO | MOZNO | ANO |
7 | 01 (1) | 11 (3) | MOZNO | MOZNO | ANO |
8 | 10 (2) | 00 (0) | MOZNO | NIE | NIE |
9 | 10 (2) | 01 (1) | MOZNO | MOZNO | ANO |
10 | 10 (2) | 10 (2) | NIE | NIE | NIE |
11 | 10 (2) | 11 (3) | MOZNO | MOZNO | ANO |
12 | 11 (3) | 00 (0) | MOZNO | NIE | NIE |
13 | 11 (3) | 01 (1) | MOZNO | MOZNO | ANO |
14 | 11 (3) | 10 (2) | MOZNO | MOZNO | ANO |
15 | 11 (3) | 11 (3) | NIE | NIE | NIE |
$n^2$ je dostatočne veľa na všetko