Skip to content

Commit c919a7c

Browse files
committed
Merge branch 'master' of github.com:VitamintK/AlgorithmProblems
2 parents c74da9d + e7d8541 commit c919a7c

File tree

4 files changed

+293
-0
lines changed

4 files changed

+293
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from collections import defaultdict, deque, Counter
2+
# d = deque()
3+
# d.append(5)
4+
# x = d.popleft()
5+
import re
6+
# m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
7+
# # or re.search
8+
# >>> m.group(0) # The entire match
9+
# 'Isaac Newton'
10+
# >>> m.group(1) # The first parenthesized subgroup.
11+
# 'Isaac'
12+
# >>> m.group(2) # The second parenthesized subgroup.
13+
# 'Newton'
14+
# >>> m.group(1, 2) # Multiple arguments give us a tuple.
15+
# ('Isaac', 'Newton')
16+
from heapq import heappush, heappop
17+
# >>> heap = []
18+
# >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
19+
# >>> for item in data:
20+
# ... heappush(heap, item)
21+
# heap[0] is the smallest item
22+
import string
23+
# string.ascii_lowercase == 'abcde...'
24+
# string.ascii_uppercase == 'ABCDE...'
25+
from functools import lru_cache
26+
# @lru_cache(maxsize=None)
27+
28+
import sys
29+
30+
sys.setrecursionlimit(100000)
31+
32+
def get_ints(s):
33+
return list(map(int, re.findall(r"-?\d+", s))) # copied from mcpower from mserrano on betaveros' recommendation
34+
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
35+
octs = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
36+
def is_grid_valid(n,m, r,c,):
37+
return (0<=r<n) and (0<=c<m)
38+
39+
if True:
40+
ans = 0
41+
inps = []
42+
while True:
43+
try:
44+
inps.append(input())
45+
except EOFError:
46+
break
47+
inps = '\n'.join(inps)
48+
inps = inps.split('\n\n')
49+
l = []
50+
ans = 0
51+
for inp in inps:
52+
inp = inp.split()
53+
cal = sum(int(x) for x in inp)
54+
l.append(cal)
55+
l.sort()
56+
y = l[-3:]
57+
print(sum(y))
58+
else:
59+
pass
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from collections import defaultdict, deque, Counter
2+
# d = deque()
3+
# d.append(5)
4+
# x = d.popleft()
5+
import re
6+
# m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
7+
# # or re.search
8+
# >>> m.group(0) # The entire match
9+
# 'Isaac Newton'
10+
# >>> m.group(1) # The first parenthesized subgroup.
11+
# 'Isaac'
12+
# >>> m.group(2) # The second parenthesized subgroup.
13+
# 'Newton'
14+
# >>> m.group(1, 2) # Multiple arguments give us a tuple.
15+
# ('Isaac', 'Newton')
16+
from heapq import heappush, heappop
17+
# >>> heap = []
18+
# >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
19+
# >>> for item in data:
20+
# ... heappush(heap, item)
21+
# heap[0] is the smallest item
22+
import string
23+
# string.ascii_lowercase == 'abcde...'
24+
# string.ascii_uppercase == 'ABCDE...'
25+
from functools import lru_cache
26+
# @lru_cache(maxsize=None)
27+
28+
import sys
29+
30+
sys.setrecursionlimit(100000)
31+
32+
def get_ints(s):
33+
return list(map(int, re.findall(r"-?\d+", s))) # copied from mcpower from mserrano on betaveros' recommendation
34+
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
35+
octs = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
36+
def is_grid_valid(n,m, r,c,):
37+
return (0<=r<n) and (0<=c<m)
38+
39+
40+
if False:
41+
mapp = {'A':0, 'B':1, 'C':2, 'X':0, 'Y':1, 'Z':2}
42+
ans = 0
43+
inps = []
44+
while True:
45+
try:
46+
inps.append(input())
47+
except EOFError:
48+
break
49+
for inp in inps:
50+
x,y = inp.split()
51+
x,y = mapp[x], mapp[y]
52+
score = y+1
53+
if (y-x)%3 == 1:
54+
score += 6
55+
elif y==x:
56+
score += 3
57+
else:
58+
score += 0
59+
ans += score
60+
61+
62+
63+
print(ans)
64+
else:
65+
mapp = {'A':0, 'B':1, 'C':2, 'X':-1, 'Y':0, 'Z':1}
66+
ans = 0
67+
inps = []
68+
while True:
69+
try:
70+
inps.append(input())
71+
except EOFError:
72+
break
73+
for inp in inps:
74+
x,y = inp.split()
75+
x,y = mapp[x], mapp[y]
76+
y = (x+y)%3
77+
score = y+1
78+
if (y-x)%3 == 1:
79+
score += 6
80+
elif y==x:
81+
score += 3
82+
else:
83+
score += 0
84+
ans += score
85+
86+
87+
88+
print(ans)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from collections import defaultdict, deque, Counter
2+
# d = deque()
3+
# d.append(5)
4+
# x = d.popleft()
5+
import re
6+
# m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
7+
# # or re.search
8+
# >>> m.group(0) # The entire match
9+
# 'Isaac Newton'
10+
# >>> m.group(1) # The first parenthesized subgroup.
11+
# 'Isaac'
12+
# >>> m.group(2) # The second parenthesized subgroup.
13+
# 'Newton'
14+
# >>> m.group(1, 2) # Multiple arguments give us a tuple.
15+
# ('Isaac', 'Newton')
16+
from heapq import heappush, heappop
17+
# >>> heap = []
18+
# >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
19+
# >>> for item in data:
20+
# ... heappush(heap, item)
21+
# heap[0] is the smallest item
22+
import string
23+
# string.ascii_lowercase == 'abcde...'
24+
# string.ascii_uppercase == 'ABCDE...'
25+
from functools import lru_cache
26+
# @lru_cache(maxsize=None)
27+
28+
import sys
29+
30+
sys.setrecursionlimit(100000)
31+
32+
def get_ints(s):
33+
return list(map(int, re.findall(r"-?\d+", s))) # copied from mcpower from mserrano on betaveros' recommendation
34+
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
35+
octs = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
36+
def is_grid_valid(n,m, r,c,):
37+
return (0<=r<n) and (0<=c<m)
38+
39+
if False:
40+
ans = 0
41+
inps = []
42+
while True:
43+
try:
44+
inps.append(input())
45+
except EOFError:
46+
break
47+
for inp in inps:
48+
l = len(inp)
49+
a = inp[:l//2]
50+
b = inp[l//2:]
51+
s = set(a) & set(b)
52+
assert len(s) == 1
53+
x = list(s)[0]
54+
print(x)
55+
if ord(x) < ord('a'):
56+
y = ord(x) - ord('A') + 27
57+
else:
58+
y = ord(x) - ord('a') + 1
59+
ans += y
60+
print(y)
61+
62+
63+
print(ans)
64+
else:
65+
ans = 0
66+
inps = []
67+
while True:
68+
try:
69+
inps.append(input())
70+
except EOFError:
71+
break
72+
for x in range(0,len(inps), 3):
73+
strings = inps[x:x+3]
74+
s = set(strings[0]) & set(strings[1]) & set(strings[2])
75+
assert len(s) == 1
76+
x = list(s)[0]
77+
print(x)
78+
if ord(x) < ord('a'):
79+
y = ord(x) - ord('A') + 27
80+
else:
81+
y = ord(x) - ord('a') + 1
82+
ans += y
83+
print(y)
84+
85+
86+
print(ans)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from collections import defaultdict, deque, Counter
2+
# d = deque()
3+
# d.append(5)
4+
# x = d.popleft()
5+
import re
6+
# m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
7+
# # or re.search
8+
# >>> m.group(0) # The entire match
9+
# 'Isaac Newton'
10+
# >>> m.group(1) # The first parenthesized subgroup.
11+
# 'Isaac'
12+
# >>> m.group(2) # The second parenthesized subgroup.
13+
# 'Newton'
14+
# >>> m.group(1, 2) # Multiple arguments give us a tuple.
15+
# ('Isaac', 'Newton')
16+
from heapq import heappush, heappop
17+
# >>> heap = []
18+
# >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
19+
# >>> for item in data:
20+
# ... heappush(heap, item)
21+
# heap[0] is the smallest item
22+
import string
23+
# string.ascii_lowercase == 'abcde...'
24+
# string.ascii_uppercase == 'ABCDE...'
25+
from functools import lru_cache
26+
# @lru_cache(maxsize=None)
27+
28+
import sys
29+
30+
sys.setrecursionlimit(100000)
31+
32+
def get_ints(s):
33+
return list(map(int, re.findall(r"-?\d+", s))) # copied from mcpower from mserrano on betaveros' recommendation
34+
dirs = [(0,1), (1,0), (0,-1), (-1,0)]
35+
octs = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
36+
def is_grid_valid(n,m, r,c,):
37+
return (0<=r<n) and (0<=c<m)
38+
39+
if True:
40+
ans = 0
41+
inps = []
42+
while True:
43+
try:
44+
inps.append(input())
45+
except EOFError:
46+
break
47+
for inp in inps:
48+
a,b = inp.split(',')
49+
a = [int(x) for x in a.split('-')]
50+
b = [int(x) for x in b.split('-')]
51+
if a[0] > b[0]:
52+
a,b = b,a
53+
# if (a[0] <= b[0] and a[1] >= b[1]) or (b[0] <= a[0] and b[1] >= a[1]):
54+
# ans += 1
55+
if (b[0] <= a[0] <= b[1]) or (a[0] <= b[0] <= a[1]):
56+
ans += 1
57+
58+
print(ans)
59+
else:
60+
pass

0 commit comments

Comments
 (0)