Все задачи на 5.10.17 13:00
This commit is contained in:
41
uts/session_py/1.py
Normal file
41
uts/session_py/1.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from random import randint
|
||||
#x=int(input())
|
||||
#y=int(input())
|
||||
x=10
|
||||
y=10
|
||||
sum=0;
|
||||
maxoffset = 0;
|
||||
cordx=0;
|
||||
cordy=0;
|
||||
mini = min(x,y)
|
||||
mass = [[randint(0,1) for i in range(x)] for o in range(y)]
|
||||
for i in range(y):
|
||||
print(mass[i])
|
||||
for i in range(y):
|
||||
for o in range(x):
|
||||
if mass[i][o] == 0:
|
||||
sum=0;
|
||||
ii = 0;
|
||||
#print("found zero at ",o,i)
|
||||
for ii in range(mini):
|
||||
if ii+o >= x:
|
||||
break
|
||||
if ii+i >= y:
|
||||
break
|
||||
sum = sum + mass[i + ii][o + ii]
|
||||
for oo in range(ii):
|
||||
sum = sum + mass[i+ii][o+oo]
|
||||
sum = sum + mass[i+oo][o+ii]
|
||||
if sum != 0:
|
||||
break
|
||||
#print("end zero at offset", ii)
|
||||
if (maxoffset< ii):
|
||||
maxoffset = ii
|
||||
cordx = o
|
||||
cordy = i
|
||||
#print("!write bigger offset")
|
||||
print(cordx+1, cordy+1, cordx+maxoffset, cordy+maxoffset)
|
||||
print('these numbers should be zeroes')
|
||||
for i in range(cordy,cordy+maxoffset):
|
||||
for o in range(cordx,cordx+maxoffset):
|
||||
print(mass[i][o])
|
||||
13
uts/session_py/10.py
Normal file
13
uts/session_py/10.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from random import *
|
||||
from math import *
|
||||
|
||||
n = 10000
|
||||
k = 0
|
||||
|
||||
for i in range(n):
|
||||
x = uniform(-sqrt(2)/3, sqrt(2)/3)
|
||||
y = uniform(-sqrt(2)/3, sqrt(2)/3)
|
||||
z = uniform(-sqrt(2)/3, sqrt(2)/3)
|
||||
if ():
|
||||
k+=1
|
||||
print(k/n)
|
||||
8
uts/session_py/18.02.17.py
Normal file
8
uts/session_py/18.02.17.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import sys
|
||||
sys.stdin = open("sta.txt", "r")
|
||||
|
||||
sta, n = list(map(int, input().split()))
|
||||
s = []
|
||||
for i in range(sta):
|
||||
s.append(input())
|
||||
print(s)
|
||||
7
uts/session_py/2.py
Normal file
7
uts/session_py/2.py
Normal file
@@ -0,0 +1,7 @@
|
||||
n=7
|
||||
mass = [[1 for i in range(n)]]
|
||||
current_max = 1;
|
||||
print(mass)
|
||||
for i in range(1,n):
|
||||
current_max = current_max +1;
|
||||
cur_list = mass[i-1]
|
||||
41
uts/session_py/3.py
Normal file
41
uts/session_py/3.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
|
||||
problem_name = str('calendar')
|
||||
sys.stdin = open(problem_name + ".in", "r")
|
||||
# sys.stdout = open(problem_name+".out", "w")
|
||||
|
||||
def get_mass(num):
|
||||
arr = []
|
||||
n = num
|
||||
while n > 0:
|
||||
arr.append(n%10)
|
||||
n = n//10
|
||||
return arr
|
||||
|
||||
def bad_char(start, end, bad):
|
||||
counterr = 0
|
||||
for day in range(start, end):
|
||||
an = get_mass(day)
|
||||
for nu in num:
|
||||
if nu in an:
|
||||
counterr += 1
|
||||
return counterr
|
||||
|
||||
|
||||
n, k = map(int, input().split())
|
||||
a = list(map(int, input().split()))
|
||||
num = list(map(int, input().split()))
|
||||
print(n,' ',k)
|
||||
counter = 0
|
||||
a.sort()
|
||||
print(a)
|
||||
lastmas = 0
|
||||
lastcount = 0
|
||||
|
||||
for mounth in a:
|
||||
if lastmas == mounth:
|
||||
counter = counter + lastcount
|
||||
else:
|
||||
counter = counter + lastcount + lastcount + bad_char(lastmas, mounth, num)
|
||||
lastmas = mounth
|
||||
print(counter)
|
||||
10
uts/session_py/4.py
Normal file
10
uts/session_py/4.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import sys
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
n = int(input())
|
||||
count = 0
|
||||
for i in range(n):
|
||||
for j in list(map(int, input().split())):
|
||||
count = count + j
|
||||
count = count / 2
|
||||
print(int(count))
|
||||
9
uts/session_py/5.py
Normal file
9
uts/session_py/5.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import sys
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
n, m = map(int, input().split())
|
||||
n_mas = [0 for i in range(n)]
|
||||
for i in range(m):
|
||||
for j in list(map(int, input().split())):
|
||||
n_mas[j-1] += 1
|
||||
print(*n_mas)
|
||||
19
uts/session_py/6.py
Normal file
19
uts/session_py/6.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
n, m = map(int, input().split())
|
||||
mas = []
|
||||
for i in range(n):
|
||||
mas.append(list(map(int, input().split())))
|
||||
ans = [[0 for i in range(m)] for j in range(n)]
|
||||
for i in range(n):
|
||||
for j in range(m):
|
||||
dist = 1000
|
||||
for k in range(n):
|
||||
for l in range(m):
|
||||
if mas[k][l] == 1:
|
||||
dist = min(dist, abs(k - i) + abs(l-j))
|
||||
ans[i][j] = dist
|
||||
for i in range(len(ans)):
|
||||
print(*ans[i])
|
||||
#http://127.0.0.1:41017/
|
||||
10
uts/session_py/7.py
Normal file
10
uts/session_py/7.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from random import randint
|
||||
|
||||
k = 0
|
||||
n = 100000
|
||||
|
||||
for i in range(n):
|
||||
h = randint(1,6)
|
||||
if (h == 2) or (h == 5):
|
||||
k += 1;
|
||||
print(k/n)
|
||||
11
uts/session_py/8.py
Normal file
11
uts/session_py/8.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from random import *
|
||||
|
||||
n = 10000
|
||||
k = 0
|
||||
|
||||
for i in range(n):
|
||||
y = randint(0, 7) + random()
|
||||
x = randint(0, 9) + random()
|
||||
if (y <= 4 * x) and (y <= 10-x) and (y >= 0):
|
||||
k += 1
|
||||
print((k/n)*80)
|
||||
13
uts/session_py/9.py
Normal file
13
uts/session_py/9.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from random import *
|
||||
|
||||
from math import cos, pi
|
||||
|
||||
n = 10000
|
||||
k = 0
|
||||
for i in range(n):
|
||||
y = uniform(-1, 1)
|
||||
x = uniform(-pi, pi)
|
||||
if ((y <= cos(x)) and (x >= -pi) and (x <= pi) and (y >= 0)) \
|
||||
or ((y >= cos(x)) and (x >= -pi) and (x <= pi) and (y <= 0)):
|
||||
k += 1
|
||||
print(k/n*pi*4)
|
||||
26
uts/session_py/B.py
Normal file
26
uts/session_py/B.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
problem_name = str('input')
|
||||
sys.stdin = open(problem_name + ".txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
|
||||
n, m = map(int, input().split())
|
||||
n_mas = list(map(int, input().split()))
|
||||
m_mas = list(map(int, input().split()))
|
||||
s = []
|
||||
for i in n_mas:
|
||||
if not (i in m_mas):
|
||||
s.append(i)
|
||||
for i in m_mas:
|
||||
if not (i in n_mas):
|
||||
s.append(i)
|
||||
if s == []:
|
||||
print('EQUAL')
|
||||
else:
|
||||
s.sort()
|
||||
for i in s:
|
||||
if i in n_mas:
|
||||
print('+'+str(i))
|
||||
else:
|
||||
print('-'+str(i))
|
||||
#vlaDDisLaVuYtk
|
||||
10
uts/session_py/C.py
Normal file
10
uts/session_py/C.py
Normal file
@@ -0,0 +1,10 @@
|
||||
w, h, xo, yo, x, y = map(int, input().split())
|
||||
|
||||
l = abs(x-xo)+abs(y-yo)
|
||||
ll = yo + abs(h-y) + abs(x-xo)
|
||||
lll = h-yo+y+abs(x-xo)
|
||||
llll = xo+abs(w-x)+abs(y-yo)
|
||||
lllll = w-xo+x+abs(y-yo)
|
||||
llllll = xo+yo+abs(h-y)+abs(w-x)
|
||||
lllllll = abs(h-yo)+abs(w-xo)+x+y
|
||||
print(min(l,ll,lll,llll,lllll,llllll,lllllll))
|
||||
18
uts/session_py/Check.py
Normal file
18
uts/session_py/Check.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
sys.stdin = open("input.txt", "r")
|
||||
#sys.stdout = open("output.txt", "w")
|
||||
|
||||
def dfs(graph, start):
|
||||
visited, stack = set(), [start]
|
||||
while stack:
|
||||
vertex = stack.pop()
|
||||
if vertex not in visited:
|
||||
visited.add(vertex)
|
||||
stack.extend(graph[vertex] - visited)
|
||||
return visited
|
||||
|
||||
n = int(input())
|
||||
mas = [list(map(int, input().split())) for i in range(n)]
|
||||
visit = []
|
||||
|
||||
print(mas)
|
||||
35
uts/session_py/E.py
Normal file
35
uts/session_py/E.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import sys
|
||||
problem_name = str('input')
|
||||
sys.stdout = open("output.txt", "w")
|
||||
def unff(number, arr, base):
|
||||
res = ""
|
||||
while number > 0:
|
||||
y = arr[number % base]
|
||||
res = y + res
|
||||
number = int(number // base)
|
||||
return res
|
||||
dec_mas = []
|
||||
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
|
||||
f = open(problem_name + ".txt")
|
||||
s = []
|
||||
for line in f:
|
||||
s.append(line)
|
||||
for od in range(1, len(s)):
|
||||
dec_mas.append(int(s[od]))
|
||||
b = int(s[0])
|
||||
count = {}
|
||||
count = {i: 0 for i in arr}
|
||||
for i in dec_mas:
|
||||
un = unff(i, arr, b)
|
||||
s = []
|
||||
for o in un:
|
||||
if not(o in s):
|
||||
count[o] += 1
|
||||
s.append(o)
|
||||
maxim = 0
|
||||
index = 0
|
||||
for i in count:
|
||||
if count[i] > maxim:
|
||||
maxim = count[i]
|
||||
index = i
|
||||
print(index)
|
||||
4
uts/session_py/J.py
Normal file
4
uts/session_py/J.py
Normal file
@@ -0,0 +1,4 @@
|
||||
n = int(input())
|
||||
matx = []
|
||||
for i in range(n):
|
||||
matx.append(list(map(int, input().split())))
|
||||
2
uts/session_py/O2017_MT/kek.in
Normal file
2
uts/session_py/O2017_MT/kek.in
Normal file
@@ -0,0 +1,2 @@
|
||||
В сто сорок солнц закат пылал, в июль катилось лето.
|
||||
Мы не рабы, рабы не мы.
|
||||
18
uts/session_py/O2017_MT/УВВ_ZZ1.py
Normal file
18
uts/session_py/O2017_MT/УВВ_ZZ1.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def swi(g):
|
||||
if g == 1:
|
||||
return 0, False
|
||||
if g == 0:
|
||||
return 1, True
|
||||
a = input()
|
||||
b = input()
|
||||
ex = []
|
||||
g = 0
|
||||
for i in b:
|
||||
g, doo = swi(g)
|
||||
if (doo) and (not (i in ex)):
|
||||
ex.append(i)
|
||||
b = ''
|
||||
for i in a:
|
||||
if not (i in ex):
|
||||
b += i
|
||||
print(b)
|
||||
3
uts/session_py/calendar.in
Normal file
3
uts/session_py/calendar.in
Normal file
@@ -0,0 +1,3 @@
|
||||
12 2
|
||||
31 28 31 30 31 30 31 31 30 31 30 31
|
||||
0 3
|
||||
20
uts/session_py/dist_march_2k17/Business.py
Normal file
20
uts/session_py/dist_march_2k17/Business.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
|
||||
n = int(input())
|
||||
c = [None for i in range(n+1)]
|
||||
for i in range(1, n, 2):
|
||||
c[i] = 0
|
||||
c[2] = 1
|
||||
c[0] = 1
|
||||
def recursion(n, c):
|
||||
if c[n] != None:
|
||||
return c[n]
|
||||
kkk = 0
|
||||
for i in range(1, n):
|
||||
kkk += recursion(i-1, c) * recursion(n-i-1, c)
|
||||
c[n] = kkk
|
||||
return kkk
|
||||
print(recursion(n, c))
|
||||
26
uts/session_py/dist_march_2k17/Peter.py
Normal file
26
uts/session_py/dist_march_2k17/Peter.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
s = int(input())
|
||||
l = 1
|
||||
h = int(10e18)
|
||||
while l <= h:
|
||||
mid = (l+h)//2
|
||||
x = mid
|
||||
now = mid
|
||||
while x != 0:
|
||||
st = str(x)
|
||||
st = st[:-1]
|
||||
if len(st) == 0:
|
||||
break
|
||||
x = int(st)
|
||||
now += x
|
||||
if now == s :
|
||||
print(mid)
|
||||
quit()
|
||||
elif now < s :
|
||||
l = mid + 1
|
||||
else :
|
||||
h = mid - 1
|
||||
print(-1)
|
||||
24
uts/session_py/dist_march_2k17/Sherlock.py
Normal file
24
uts/session_py/dist_march_2k17/Sherlock.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
|
||||
test_num = int(input())
|
||||
for test in range(test_num):
|
||||
b = 'NO'
|
||||
n = int(input())
|
||||
a = list(map(int, input().split()))
|
||||
if n == 1:
|
||||
b = 'YES'
|
||||
elif n == 2:
|
||||
b = 'NO'
|
||||
else:
|
||||
left = 0
|
||||
right = sum(a[1:])
|
||||
for i in range(1, n-1):
|
||||
left += a[i - 1]
|
||||
right -= a[i]
|
||||
if left == right:
|
||||
b = 'YES'
|
||||
break
|
||||
print(b)
|
||||
16
uts/session_py/dist_march_2k17/String.py
Normal file
16
uts/session_py/dist_march_2k17/String.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
orig, end = input(), input()
|
||||
|
||||
while len(end) > len(orig):
|
||||
if end[-1] == 'A':
|
||||
end = end[:-1]
|
||||
else:
|
||||
end = end[:-1][::-1]
|
||||
|
||||
if orig == end:
|
||||
print('POSSIBLE')
|
||||
else:
|
||||
print('IMPOSSIBLE')
|
||||
1
uts/session_py/dist_march_2k17/input.txt
Normal file
1
uts/session_py/dist_march_2k17/input.txt
Normal file
@@ -0,0 +1 @@
|
||||
50
|
||||
6
uts/session_py/input.txt
Normal file
6
uts/session_py/input.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
0 1 3 1 4
|
||||
1 0 4 5 2
|
||||
3 4 0 8 4
|
||||
1 5 8 0 3
|
||||
4 2 4 3 0
|
||||
1
uts/session_py/output.txt
Normal file
1
uts/session_py/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
|
||||
9
uts/session_py/sta.txt
Normal file
9
uts/session_py/sta.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
8 15
|
||||
Музыкальная
|
||||
Историческая
|
||||
Минное поле
|
||||
Арм рестлинг
|
||||
Математическая
|
||||
Волейбол
|
||||
ОБЖ
|
||||
Перевязочная
|
||||
Reference in New Issue
Block a user