mirror of
https://github.com/Xevion/contest.git
synced 2025-12-09 16:06:48 -06:00
update spaced icpc contest folder to kebab case repository formatting
This commit is contained in:
5
icpc/ecna-regional-contest-2018/A/input
Normal file
5
icpc/ecna-regional-contest-2018/A/input
Normal file
@@ -0,0 +1,5 @@
|
||||
90 80 4
|
||||
60 35 25
|
||||
50 140 35
|
||||
195 165 25
|
||||
195 40 40
|
||||
28
icpc/ecna-regional-contest-2018/A/main.py
Normal file
28
icpc/ecna-regional-contest-2018/A/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import sys, os, math
|
||||
|
||||
# Pythagorean Distance Formula
|
||||
def pyth(x1, y1, x2, y2):
|
||||
return math.sqrt(((x1 - x2) ** 2) + ((y1 - y2) ** 2))
|
||||
|
||||
def dist(spot1, spot2):
|
||||
return pyth(spot1[0], spot1[1], spot2[0], spot2[1])
|
||||
|
||||
def main():
|
||||
def parse(dat):
|
||||
return list(map(int, dat.split()))
|
||||
|
||||
|
||||
path = os.path.join(sys.path[0], 'input')
|
||||
data = open(path, 'r').read().split('\n')
|
||||
listeners = []
|
||||
|
||||
|
||||
for dataset in data:
|
||||
listeners.append(parse(dataset))
|
||||
spy = listeners.pop(0)
|
||||
|
||||
distances = sorted(list(map(lambda x : dist(spy, x), listeners)))
|
||||
print(int(distances[:2][-1]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
icpc/ecna-regional-contest-2018/B/inputs/1
Normal file
1
icpc/ecna-regional-contest-2018/B/inputs/1
Normal file
@@ -0,0 +1 @@
|
||||
24
|
||||
1
icpc/ecna-regional-contest-2018/B/inputs/2
Normal file
1
icpc/ecna-regional-contest-2018/B/inputs/2
Normal file
@@ -0,0 +1 @@
|
||||
25
|
||||
1
icpc/ecna-regional-contest-2018/B/inputs/3
Normal file
1
icpc/ecna-regional-contest-2018/B/inputs/3
Normal file
@@ -0,0 +1 @@
|
||||
987654321
|
||||
17
icpc/ecna-regional-contest-2018/B/main.py
Normal file
17
icpc/ecna-regional-contest-2018/B/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import os, sys
|
||||
|
||||
def harshad(n):
|
||||
return (n % sum(map(int, list(str(n))))) == 0
|
||||
|
||||
def main():
|
||||
inputs = [os.path.join(sys.path[0], 'inputs', x) for x in
|
||||
os.listdir(os.path.join(sys.path[0], 'inputs'))]
|
||||
inputs = [int(open(path).read()) for path in inputs]
|
||||
|
||||
for i in inputs:
|
||||
while not harshad(i):
|
||||
i += 1
|
||||
print(i)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
4
icpc/ecna-regional-contest-2018/C/input
Normal file
4
icpc/ecna-regional-contest-2018/C/input
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
Oh say can you see
|
||||
I do not understand why you are so cranky just because Karel won
|
||||
Formation
|
||||
65
icpc/ecna-regional-contest-2018/C/main.py
Normal file
65
icpc/ecna-regional-contest-2018/C/main.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import os, sys
|
||||
|
||||
mappings = {
|
||||
'@' : ['at'],
|
||||
'&' : ['and'],
|
||||
'1' : ['one', 'won'],
|
||||
'2' : ['to', 'too', 'two'],
|
||||
'4' : ['for', 'four'],
|
||||
'b' : ['bea', 'be', 'bee'],
|
||||
'c' : ['sea', 'see'],
|
||||
'i' : ['eye'],
|
||||
'o' : ['oh', 'owe'],
|
||||
'r' : ['are'],
|
||||
'u' : ['you'],
|
||||
'y' : ['why']
|
||||
}
|
||||
|
||||
# gets the largest and smallest possible subs
|
||||
minSub = min([min(list(map(len, vals))) for vals in mappings.values()])
|
||||
maxSub = max([max(list(map(len, vals))) for vals in mappings.values()])
|
||||
|
||||
# Gets the token ('are' -> 'r') for a sub, case sensitive
|
||||
def getToken(sub):
|
||||
for key in mappings.keys():
|
||||
if sub in mappings[key]:
|
||||
return key
|
||||
|
||||
def processWord(word):
|
||||
processed = [False] * len(word)
|
||||
# For every character in the word
|
||||
index = 0
|
||||
while index < len(word):
|
||||
possible = []
|
||||
for length in range(minSub, maxSub + 1):
|
||||
if index + length > len(word):
|
||||
continue
|
||||
sub = word[index:index + length]
|
||||
token = getToken(sub.lower())
|
||||
if token:
|
||||
# Sometimes mulitple tokens can appear for the same one, we just select the one that is longest
|
||||
possible.append((token, len(sub), sub))
|
||||
# A token replacement has been found at this index
|
||||
if possible:
|
||||
# Find the best one, based on the sub
|
||||
select = max(possible, key=lambda item : item[1])
|
||||
# print(index, select, word[index:index + select[1]])
|
||||
word = word[:index] + (select[0].title() if select[2].istitle() else select[0]) + word[index + select[1]:]
|
||||
# word[index:index + select[1]] = select[0]
|
||||
index += len(select[0])
|
||||
else:
|
||||
index += 1
|
||||
return word
|
||||
|
||||
# Process a single line
|
||||
def processLine(line):
|
||||
return ' '.join([processWord(word) for word in line.split(' ')])
|
||||
|
||||
# Drive Code
|
||||
def main():
|
||||
path = os.path.join(sys.path[0], 'input')
|
||||
data = open(path, 'r').read().split('\n')[1:]
|
||||
print('\n'.join(map(processLine, data)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
6
icpc/ecna-regional-contest-2018/D/inputs/1
Normal file
6
icpc/ecna-regional-contest-2018/D/inputs/1
Normal file
@@ -0,0 +1,6 @@
|
||||
5
|
||||
H 2 0:13
|
||||
A 2 0:19
|
||||
H 1 0:52
|
||||
H 1 0:52
|
||||
A 3 1:08
|
||||
2
icpc/ecna-regional-contest-2018/D/inputs/2
Normal file
2
icpc/ecna-regional-contest-2018/D/inputs/2
Normal file
@@ -0,0 +1,2 @@
|
||||
1
|
||||
H 1 16:00
|
||||
41
icpc/ecna-regional-contest-2018/D/main.py
Normal file
41
icpc/ecna-regional-contest-2018/D/main.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import datetime, re, os, sys
|
||||
|
||||
pattern = r'([HA]) (\d) (\d+):(\d+)'
|
||||
mmsspattern = '%M:%S'
|
||||
|
||||
# Process the input for a single niput
|
||||
def process(rawinput):
|
||||
def getBest():
|
||||
return max(score.items(), key=lambda x:x[1])[0]
|
||||
score = {'H' : 0, 'A' : 0}
|
||||
leads = {'H' : 0, 'A' : 0}
|
||||
rawinput = '\n'.join(rawinput.split('\n')[1:])
|
||||
events = re.finditer(pattern, rawinput)
|
||||
curLead = ''
|
||||
lastTime = datetime.datetime(1990, 1, 1, 0, 0, 0)
|
||||
gameEnd = datetime.datetime(1990, 1, 1, 1, 30)
|
||||
for event in events:
|
||||
# Create the formatted timecode, add the score
|
||||
timecode = '{}:{}'.format(event.group(3).zfill(2), event.group(4).zfill(2))
|
||||
curtime = datetime.datetime.strptime(timecode, mmsspattern)
|
||||
score[event.group(1)] += int(event.group(2))
|
||||
# Get the team in the lead and if it's different
|
||||
best = getBest()
|
||||
leads[best] += int((curtime - lastTime).seconds)
|
||||
lastTime = curtime
|
||||
# if gameEnd > lastTime:
|
||||
# leads[best] += (gameEnd - lastTime).seconds
|
||||
return '{} {} {}'.format(getBest(), leads['H'], leads['A'])
|
||||
|
||||
# Driver code
|
||||
def main():
|
||||
# Read inputs
|
||||
inputs = [os.path.join(sys.path[0], 'inputs', x) for x in
|
||||
os.listdir(os.path.join(sys.path[0], 'inputs'))]
|
||||
inputs = [open(path).read() for path in inputs]
|
||||
for rawinput in inputs:
|
||||
print(process(rawinput))
|
||||
print('-'*19)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
icpc/ecna-regional-contest-2018/E/inputs/1
Normal file
1
icpc/ecna-regional-contest-2018/E/inputs/1
Normal file
@@ -0,0 +1 @@
|
||||
725.85 1.71 2.38
|
||||
1
icpc/ecna-regional-contest-2018/E/inputs/2
Normal file
1
icpc/ecna-regional-contest-2018/E/inputs/2
Normal file
@@ -0,0 +1 @@
|
||||
100.00 20.00 10.00
|
||||
21
icpc/ecna-regional-contest-2018/E/main.py
Normal file
21
icpc/ecna-regional-contest-2018/E/main.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os, sys
|
||||
|
||||
# Process a single input
|
||||
def process(profit, pita, pizza):
|
||||
maxPita, maxPizza = int(profit / pita), int(profit / pizza)
|
||||
combos = [(x, y) for x in range(0, maxPita + 1) for y in range(0, maxPizza + 1)]
|
||||
combos = filter(lambda item : profit == (pita * item[0]) + (pizza * item[1]), combos)
|
||||
return '\n'.join(' '.join(map(str, combo)) for combo in combos)
|
||||
|
||||
# Driver code for all inputs in folder
|
||||
def main():
|
||||
# Read inputs
|
||||
inputs = [os.path.join(sys.path[0], 'inputs', x) for x in
|
||||
os.listdir(os.path.join(sys.path[0], 'inputs'))]
|
||||
# Parse inputs
|
||||
inputs = [list(map(float, open(path).read().split())) for path in inputs]
|
||||
# Process inputs and print outputs
|
||||
print('\n{}\n'.format('-' * 10).join(map(lambda item : process(*item), inputs)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
2
icpc/ecna-regional-contest-2018/F/inputs/1
Normal file
2
icpc/ecna-regional-contest-2018/F/inputs/1
Normal file
@@ -0,0 +1,2 @@
|
||||
14 2 3
|
||||
5 6 9 8 5 4 6 5 2 3 6 8 7 4
|
||||
2
icpc/ecna-regional-contest-2018/F/inputs/2
Normal file
2
icpc/ecna-regional-contest-2018/F/inputs/2
Normal file
@@ -0,0 +1,2 @@
|
||||
14 3 2
|
||||
5 6 9 8 5 4 6 5 2 3 6 8 7 4
|
||||
56
icpc/ecna-regional-contest-2018/F/main.py
Normal file
56
icpc/ecna-regional-contest-2018/F/main.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import os, sys
|
||||
|
||||
def process(item):
|
||||
# Constants and initial values
|
||||
stocks, (n, m) = item[1], item[0]
|
||||
peaks, valleys = [], []
|
||||
# Check all possible peaks
|
||||
for index in range(len(stocks)):
|
||||
isPeak, isValley = True, True
|
||||
# Peak Checking
|
||||
for i in range(1, n + 1):
|
||||
# If we're no the first index
|
||||
if index - i >= 0:
|
||||
# If position behind us is lower
|
||||
if not stocks[index] > stocks[index - i]:
|
||||
isPeak = False
|
||||
break
|
||||
# If we're not the final index
|
||||
if index + i < len(stocks):
|
||||
# and position in front of us is lower
|
||||
if not stocks[index] > stocks[index + i]:
|
||||
isPeak = False
|
||||
break
|
||||
# Valley checking
|
||||
for i in range(1, m + 1):
|
||||
# If we're not the first index
|
||||
if index - i >= 0:
|
||||
# if position behind us is higher
|
||||
if not stocks[index] < stocks[index - i]:
|
||||
isValley = False
|
||||
break
|
||||
# If we're not the final index
|
||||
if index + i < len(stocks):
|
||||
# and position in front of us is higher
|
||||
if not stocks[index] < stocks[index + i]:
|
||||
isValley = False
|
||||
break
|
||||
if isPeak: peaks.append(index)
|
||||
if isValley: valleys.append(index)
|
||||
print(f'n{n}, m{m}')
|
||||
print('{0}{1}\n{0}{2}'.format('-> ', peaks, valleys))
|
||||
return len(peaks), len(valleys)
|
||||
|
||||
# Driver code for all inputs in folder
|
||||
def main():
|
||||
def parse(input):
|
||||
return [list(map(int, input[0].split()))[1:], list(map(int, input[1].split()))]
|
||||
# Read inputs
|
||||
inputs = [os.path.join(sys.path[0], 'inputs', x) for x in
|
||||
os.listdir(os.path.join(sys.path[0], 'inputs'))]
|
||||
inputs = [parse(open(path).read().split('\n')) for path in inputs]
|
||||
# Parse inputs
|
||||
print('\n{}\n'.format('-' * 10).join(map(lambda item : str(process(item)), inputs)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
31
icpc/ecna-regional-contest-2018/README.MD
Normal file
31
icpc/ecna-regional-contest-2018/README.MD
Normal file
@@ -0,0 +1,31 @@
|
||||
# 2018 ICPC East Central North America Regional Contest
|
||||
|
||||
## Resources
|
||||
|
||||
**[Contest Landing Page](http://acm-ecna.ysu.edu/PastResults/2018/home.html)** | **[Practice Problem Set](./prac2018.pdf)** | **[Real Problem Set](./ecna2018.pdf)**
|
||||
|
||||
## Practice Contest
|
||||
|
||||
| Letter | Problem Name | Status |
|
||||
|--------|--------------------------------|----------|
|
||||
| A | Are You Listening | Solved |
|
||||
| B | Harshad Numbers | Solved |
|
||||
| C | An I for an Eye | Unsolved |
|
||||
| D | Score! | Solved |
|
||||
| E | So You like Your Food Hot? | Solved |
|
||||
| F | The Ups and Downs of Investing | Solved |
|
||||
|
||||
## Real Contest
|
||||
|
||||
| Letter | Problem Name | Status |
|
||||
|--------|--------------------------------|----------|
|
||||
| A | Car Vet | Unsolved |
|
||||
| B | Difference | Unsolved |
|
||||
| C | Pear-wise Voting | Unsolved |
|
||||
| D | Pizza Cutting | Unsolved |
|
||||
| E | The Punctilious Cruciverbalist | Unsolved |
|
||||
| F | A Random Problem | Unsolved |
|
||||
| G | Roman Holidays | Unsolved |
|
||||
| H | Sequential Yahtzee | Unsolved |
|
||||
| I | Tours de Sales Force | Unsolved |
|
||||
| J | Watch Where You Step | Unsolved |
|
||||
BIN
icpc/ecna-regional-contest-2018/ecna2018.pdf
Normal file
BIN
icpc/ecna-regional-contest-2018/ecna2018.pdf
Normal file
Binary file not shown.
BIN
icpc/ecna-regional-contest-2018/prac2018.pdf
Normal file
BIN
icpc/ecna-regional-contest-2018/prac2018.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user