Все задачи на 5.10.17 13:00
This commit is contained in:
180
uts/uts_2017_sum_py/1/RAW.py
Normal file
180
uts/uts_2017_sum_py/1/RAW.py
Normal file
@@ -0,0 +1,180 @@
|
||||
#RZ2T(CAM)_7.py:
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n = int(input())
|
||||
a = list(map(int, input().split()))
|
||||
t = int(input())
|
||||
|
||||
a.sort()
|
||||
u, y = 0, 0
|
||||
for i in range(t):
|
||||
x = list(map(int, input().split()))
|
||||
if x[0] == 1:
|
||||
u = u + 1
|
||||
elif x[0] == 2:
|
||||
y = y + x[1]
|
||||
elif x[0] == 3:
|
||||
q = y / u
|
||||
d = n
|
||||
for j in range(n):
|
||||
if a[j] > q:
|
||||
d = j
|
||||
break
|
||||
print(n - d)
|
||||
|
||||
sys.stdout.close()
|
||||
|
||||
#RZ2T(CAM)_8.py:
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
x = int(input())
|
||||
a, b, c = list(map(int, input().split()))
|
||||
z = [[a, 'a'], [b, 'b'], [c, 'c']]
|
||||
z.sort()
|
||||
c, b, a = z[0], z[1], z[2]
|
||||
|
||||
for i in range(int(x / a[0]) + 1):
|
||||
for j in range(int((x - a[0]) / b[0]) + 1):
|
||||
if (x - j * b[0] - i * a[0]) % c[0] == 0:
|
||||
a[0], b[0], c[0] = i, j, (x - j * b[0] - i * a[0]) / c[0]
|
||||
|
||||
s = ''
|
||||
for i in [a, b, c]:
|
||||
if i[1] == 'a':
|
||||
s = str(i[0])
|
||||
|
||||
for i in [a, b, c]:
|
||||
if i[1] == 'b':
|
||||
s = s + ' ' + str(i[0])
|
||||
|
||||
for i in [a, b, c]:
|
||||
if i[1] == 'c':
|
||||
s = s + ' ' + str(i[0])
|
||||
|
||||
print(s)
|
||||
|
||||
sys.stdout.close()
|
||||
|
||||
#RZ2T_7.py:
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n, m = list(map(int, input().split()))
|
||||
|
||||
b = 0
|
||||
for i in range(n):
|
||||
a = list(map(int, input().split()))
|
||||
c = 0
|
||||
for j in a:
|
||||
if j == 0:
|
||||
c = c + 1
|
||||
else:
|
||||
b = max(b, c)
|
||||
c = 0
|
||||
b = max(b, c)
|
||||
|
||||
print(b)
|
||||
|
||||
sys.stdout.close()
|
||||
|
||||
#RZ2T_8.py:
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n = int(input())
|
||||
a = [list(map(int, input().split())) for i in range(n)]
|
||||
sal = []
|
||||
sup = []
|
||||
mel = []
|
||||
gar = []
|
||||
for i in a:
|
||||
sal.append(i[0])
|
||||
sup.append(i[1])
|
||||
mel.append(i[2])
|
||||
gar.append(i[3])
|
||||
from collections import Counter
|
||||
|
||||
print(Counter(sal).most_common(1)[0][0],
|
||||
Counter(sup).most_common(1)[0][0],
|
||||
Counter(mel).most_common(1)[0][0],
|
||||
Counter(gar).most_common(1)[0][0])
|
||||
|
||||
#RZ2T_9.py:
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n, m = list(map(int, input().split()))
|
||||
a = []
|
||||
for i in range(n):
|
||||
a.append(list(map(int, input().split())))
|
||||
|
||||
def check(mas):
|
||||
f = True
|
||||
for i in range(len(mas)):
|
||||
if mas[i] != mas[0]:
|
||||
f = False
|
||||
return f
|
||||
|
||||
|
||||
for i in range(len(a)):
|
||||
if not check(a[i]):
|
||||
print('NO')
|
||||
quit()
|
||||
try:
|
||||
slov = {}
|
||||
pos = 0
|
||||
last = a[pos][0]
|
||||
slov[a[pos][0]] = 0
|
||||
while a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
last = a[pos][0]
|
||||
###
|
||||
try:
|
||||
if slov[a[pos][0]]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
pass
|
||||
slov[a[pos][0]] = 0
|
||||
while a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
last = a[pos][0]
|
||||
###
|
||||
try:
|
||||
if slov[a[pos][0]]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
pass
|
||||
slov[a[pos][0]] = 0
|
||||
while len(a) != pos and a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
las = -1
|
||||
for i in slov:
|
||||
if las == -1:
|
||||
las = slov[i]
|
||||
elif las != slov[i]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
print('NO')
|
||||
quit()
|
||||
print('YES')
|
||||
21
uts/uts_2017_sum_py/1/RZ2T_8.py
Normal file
21
uts/uts_2017_sum_py/1/RZ2T_8.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n = int(input())
|
||||
a = [list(map(int, input().split())) for i in range(n)]
|
||||
sal = []
|
||||
sup = []
|
||||
mel = []
|
||||
gar = []
|
||||
for i in a:
|
||||
sal.append(i[0])
|
||||
sup.append(i[1])
|
||||
mel.append(i[2])
|
||||
gar.append(i[3])
|
||||
from collections import Counter
|
||||
print(Counter(sal).most_common(1)[0][0],
|
||||
Counter(sup).most_common(1)[0][0],
|
||||
Counter(mel).most_common(1)[0][0],
|
||||
Counter(gar).most_common(1)[0][0])
|
||||
72
uts/uts_2017_sum_py/1/RZ2T_9.py
Normal file
72
uts/uts_2017_sum_py/1/RZ2T_9.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n, m = list(map(int, input().split()))
|
||||
a = []
|
||||
for i in range(n):
|
||||
a.append(list(map(int, input().split())))
|
||||
|
||||
#for i in range(len(a)):
|
||||
# print(a[i])
|
||||
|
||||
def check(mas):
|
||||
f = True
|
||||
for i in range(len(mas)):
|
||||
if mas[i] != mas[0]:
|
||||
f = False
|
||||
return f
|
||||
|
||||
for i in range(len(a)):
|
||||
if not check(a[i]):
|
||||
print('NO')
|
||||
quit()
|
||||
try:
|
||||
slov = {}
|
||||
pos = 0
|
||||
last = a[pos][0]
|
||||
slov[a[pos][0]] = 0
|
||||
while a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
last = a[pos][0]
|
||||
###
|
||||
try:
|
||||
if slov[a[pos][0]]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
pass
|
||||
slov[a[pos][0]] = 0
|
||||
while a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
last = a[pos][0]
|
||||
###
|
||||
try:
|
||||
if slov[a[pos][0]]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
pass
|
||||
slov[a[pos][0]] = 0
|
||||
while len(a) != pos and a[pos][0] == last:
|
||||
slov[a[pos][0]] += 1
|
||||
last = a[pos][0]
|
||||
pos += 1
|
||||
|
||||
#print(slov)
|
||||
las = -1
|
||||
for i in slov:
|
||||
if las == -1:
|
||||
las = slov[i]
|
||||
elif las != slov[i]:
|
||||
print('NO')
|
||||
quit()
|
||||
except Exception:
|
||||
print('NO')
|
||||
quit()
|
||||
print('YES')
|
||||
6
uts/uts_2017_sum_py/1/input.txt
Normal file
6
uts/uts_2017_sum_py/1/input.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
1 1 3 2
|
||||
1 3 2 2
|
||||
2 2 2 2
|
||||
1 4 4 3
|
||||
2 1 1 2
|
||||
55
uts/uts_2017_sum_py/2/RZ2T(SAM)_7.py
Normal file
55
uts/uts_2017_sum_py/2/RZ2T(SAM)_7.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# RZ2T(SAM)_7.py
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
s = input()
|
||||
a = []
|
||||
for i in range(len(s)):
|
||||
try:
|
||||
if 1 <= int(s[i] + s[i+1]) <= 26:
|
||||
a.append(int(s[i] + s[i+1]))
|
||||
s = s[:i] + 'aa' + s[i+2:]
|
||||
else:
|
||||
raise Exception('No number')
|
||||
except Exception:
|
||||
try:
|
||||
if int(s[i]):
|
||||
a.append(int(s[i]))
|
||||
s = s[:i] + 'a' + s[i + 1:]
|
||||
except Exception:
|
||||
pass
|
||||
s = ''
|
||||
slov = {
|
||||
1: 'z',
|
||||
2: 'y',
|
||||
3: 'x',
|
||||
4: 'w',
|
||||
5: 'v',
|
||||
6: 'u',
|
||||
7: 't',
|
||||
8: 's',
|
||||
9: 'r',
|
||||
10: 'q',
|
||||
11: 'p',
|
||||
12: 'o',
|
||||
13: 'n',
|
||||
14: 'm',
|
||||
15: 'l',
|
||||
16: 'k',
|
||||
17: 'j',
|
||||
18: 'i',
|
||||
19: 'h',
|
||||
20: 'g',
|
||||
21: 'f',
|
||||
22: 'e',
|
||||
23: 'd',
|
||||
24: 'c',
|
||||
25: 'b',
|
||||
26: 'a',
|
||||
}
|
||||
for i in a:
|
||||
s += slov[i]
|
||||
print(s)
|
||||
# ------------------------------------------ #
|
||||
29
uts/uts_2017_sum_py/2/RZ2T(SAM)_8.py
Normal file
29
uts/uts_2017_sum_py/2/RZ2T(SAM)_8.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# RZ2T(SAM)_8.py
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
sys.stdout = open('output.txt', 'w')
|
||||
|
||||
n = int(input())
|
||||
a = list(map(int, input().split()))
|
||||
|
||||
counter_ros = 0
|
||||
counter_vio = 0
|
||||
ros = []
|
||||
vio = []
|
||||
|
||||
for i in range(1, n+1):
|
||||
if a[i-1] == i % 2:
|
||||
if i % 2 == 0:
|
||||
ros.append(i-1)
|
||||
counter_ros += 1
|
||||
else:
|
||||
vio.append(i-1)
|
||||
counter_vio += 1
|
||||
if counter_vio == counter_ros:
|
||||
print(counter_ros)
|
||||
for i in range(counter_ros):
|
||||
print(ros[i]+1, ' ', vio[i]+1)
|
||||
else:
|
||||
print(-1)
|
||||
# ------------------------------------------ #
|
||||
14
uts/uts_2017_sum_py/2/ads.py
Normal file
14
uts/uts_2017_sum_py/2/ads.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open('input.txt', 'r')
|
||||
#sys.stdout = open('output.txt', 'w')
|
||||
a = []
|
||||
try:
|
||||
while True:
|
||||
a.append(int(input()))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
a.sort()
|
||||
print(a[0])
|
||||
print(a[len(a)-1])
|
||||
29
uts/uts_2017_sum_py/2/das
Normal file
29
uts/uts_2017_sum_py/2/das
Normal file
@@ -0,0 +1,29 @@
|
||||
begin
|
||||
var n := ReadInteger();
|
||||
var roses := new integer[n];
|
||||
var count_roses := 0;
|
||||
var violets := new integer[n];
|
||||
var count_violets := 0;
|
||||
for var i := 1 to n do
|
||||
begin
|
||||
if ReadInteger() = i mod 2 then
|
||||
if i mod 2 = 0 then
|
||||
begin
|
||||
roses[count_roses] := i;
|
||||
inc(count_roses);
|
||||
end
|
||||
else
|
||||
begin
|
||||
violets[count_violets] := i;
|
||||
inc(count_violets);
|
||||
end;
|
||||
end;
|
||||
if count_roses = count_violets then
|
||||
begin
|
||||
writeln(count_roses);
|
||||
for var i := 0 to count_roses - 1 do
|
||||
println(roses[i], violets[i]);
|
||||
end
|
||||
else
|
||||
write(-1)
|
||||
end.
|
||||
16
uts/uts_2017_sum_py/2/input.txt
Normal file
16
uts/uts_2017_sum_py/2/input.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
160
|
||||
160
|
||||
185
|
||||
170
|
||||
160
|
||||
130
|
||||
110
|
||||
170
|
||||
190
|
||||
160
|
||||
160
|
||||
130
|
||||
190
|
||||
145
|
||||
210
|
||||
130
|
||||
40
uts/uts_2017_sum_py/3/A.py
Normal file
40
uts/uts_2017_sum_py/3/A.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import sys
|
||||
import itertools
|
||||
sys.stdin = open('balls.in', 'r')
|
||||
#sys.stdout = open('balls.out', 'w')
|
||||
|
||||
n = int(input())
|
||||
query = [int(input()) for i in range(n)]
|
||||
'''
|
||||
yadra = [0]
|
||||
count = 0
|
||||
storona = 2
|
||||
while count <= 300000:
|
||||
sum = 0
|
||||
for i in range(storona):
|
||||
sum += i
|
||||
storona += 1
|
||||
count += sum
|
||||
yadra.append(sum + yadra[-1])
|
||||
|
||||
print(yadra)
|
||||
yadra.pop(0)
|
||||
'''
|
||||
yadra = [1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495, 4960, 5456, 5984, 6545, 7140, 7770, 8436, 9139, 9880, 10660, 11480, 12341, 13244, 14190, 15180, 16215, 17296, 18424, 19600, 20825, 22100, 23426, 24804, 26235, 27720, 29260, 30856, 32509, 34220, 35990, 37820, 39711, 41664, 43680, 45760, 47905, 50116, 52394, 54740, 57155, 59640, 62196, 64824, 67525, 70300, 73150, 76076, 79079, 82160, 85320, 88560, 91881, 95284, 98770, 102340, 105995, 109736, 113564, 117480, 121485, 125580, 129766, 134044, 138415, 142880, 147440, 152096, 156849, 161700, 166650, 171700, 176851, 182104, 187460, 192920, 198485, 204156, 209934, 215820, 221815, 227920, 234136, 240464, 246905, 253460, 260130, 266916, 273819, 280840, 287980, 295240, 302621]
|
||||
|
||||
for coun in query:
|
||||
count = coun
|
||||
counter = 0
|
||||
index = 0
|
||||
while yadra[index + 1] <= count:
|
||||
index += 1
|
||||
late = yadra[:index+1]
|
||||
combs = 1
|
||||
flag = True
|
||||
while flag:
|
||||
for i in itertools.combinations_with_replacement(late, combs):
|
||||
if count - sum(i) == 0:
|
||||
print(combs)
|
||||
flag = False
|
||||
break
|
||||
combs += 1
|
||||
17
uts/uts_2017_sum_py/3/B.py
Normal file
17
uts/uts_2017_sum_py/3/B.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open('count.in', 'r')
|
||||
sys.stdout = open('count.out', 'w')
|
||||
|
||||
m, n = list(map(int, input().split()))
|
||||
x = [[0 for i in range(31)] for j in range(31)]
|
||||
s = 0
|
||||
for i in range(31):
|
||||
x[1][i] = 1
|
||||
for i in range(2, m+1):
|
||||
for j in range(n+1):
|
||||
for k in range(j+1):
|
||||
x[i][j] += x[i-1][k]
|
||||
for i in range(n+1):
|
||||
s += x[m][i]
|
||||
print(s)
|
||||
6
uts/uts_2017_sum_py/3/balls.in
Normal file
6
uts/uts_2017_sum_py/3/balls.in
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
1
|
||||
5
|
||||
9
|
||||
15
|
||||
91
|
||||
1
uts/uts_2017_sum_py/3/count.in
Normal file
1
uts/uts_2017_sum_py/3/count.in
Normal file
@@ -0,0 +1 @@
|
||||
3 5
|
||||
24
uts/uts_2017_sum_py/5/C.py
Normal file
24
uts/uts_2017_sum_py/5/C.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#import sys
|
||||
|
||||
#sys.stdin = open('rectangles.in', 'r')
|
||||
#sys.stdout = open('rectangles.out', 'w')
|
||||
n, m, k = map(int, input().split())
|
||||
a = [[100000, 0, 100000, 0] for i in range(k)]
|
||||
field = []
|
||||
|
||||
for i in range(n):
|
||||
field.append(list(map(int, input().split())))
|
||||
|
||||
field.reverse()
|
||||
|
||||
for i in range(n):
|
||||
for j in range(m):
|
||||
if field[i][j] > 0:
|
||||
v = field[i][j] - 1
|
||||
a[v][0] = min(a[v][0], j)
|
||||
a[v][1] = max(a[v][1], j)
|
||||
a[v][2] = min(a[v][2], i)
|
||||
a[v][3] = max(a[v][3], i)
|
||||
|
||||
for i in range(k):
|
||||
print(a[i][0], a[i][2], a[i][1] + 1, a[i][3] + 1)
|
||||
34
uts/uts_2017_sum_py/5/D.py
Normal file
34
uts/uts_2017_sum_py/5/D.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open('robot.in', 'r')
|
||||
s = input()
|
||||
|
||||
d = 0
|
||||
a = []
|
||||
f = 0
|
||||
c = 0
|
||||
x = 0
|
||||
y = 0
|
||||
for i in s:
|
||||
if i == 'S':
|
||||
if (x, y) in a:
|
||||
print(c)
|
||||
exit()
|
||||
a.append((x, y))
|
||||
c += 1
|
||||
if d == 0:
|
||||
x += 1
|
||||
if d == 1:
|
||||
y += 1
|
||||
if d == 2:
|
||||
x -= 1
|
||||
if d == 3:
|
||||
y -= 1
|
||||
if i == 'L':
|
||||
d = (d + 1) % 4
|
||||
if i == 'R':
|
||||
d = (d - 1) % 4
|
||||
if (x, y) in a:
|
||||
print(c)
|
||||
else:
|
||||
print(-1)
|
||||
5
uts/uts_2017_sum_py/5/rectangles.in
Normal file
5
uts/uts_2017_sum_py/5/rectangles.in
Normal file
@@ -0,0 +1,5 @@
|
||||
4 5 2
|
||||
0 2 2 2 2
|
||||
0 2 2 2 2
|
||||
1 1 2 2 2
|
||||
1 1 0 0 0
|
||||
1
uts/uts_2017_sum_py/5/robot.in
Normal file
1
uts/uts_2017_sum_py/5/robot.in
Normal file
@@ -0,0 +1 @@
|
||||
RSSSSLSLSSLS
|
||||
Reference in New Issue
Block a user