Skip to content

Instantly share code, notes, and snippets.

@mukulrawat1986
Created May 12, 2014 20:36
Show Gist options
  • Save mukulrawat1986/abd8244be5b74ec79103 to your computer and use it in GitHub Desktop.
Save mukulrawat1986/abd8244be5b74ec79103 to your computer and use it in GitHub Desktop.
Topcoder solutions
# SRM 620 candidate selection easy
class CandidatesSelectionEasy(object):
def sort(self, score, x):
score1 = []
for pos,val in enumerate(score):
score1.append((val,pos))
score1 = sorted(score1, key = lambda k: k[0][x])
#print score1
res = []
for pos,val in enumerate(score1):
res.append(val[1])
return res
c = CandidatesSelectionEasy()
print c.sort(["A", "C", "B", "C", "A"],0)
# SRM 619 Choose The Best One
class ChooseTheBestOne(object):
def countNumber(self, N):
# print 'for', N
li = [i for i in xrange(1,N+1)]
skip =0
idx = skip
count = 2
while len(li) > 1:
li.pop(idx)
skip = count**3
skip-=1
idx = (idx + skip) % len(li)
count+=1
return li[0]
c = ChooseTheBestOne()
print c.countNumber(3)
print c.countNumber(6)
print c.countNumber(5000)
class EmployManager(object):
def maximumEarnings(self, value, earning):
n = len(value)
# p = [0]*(n**2)
p = [0 for i in xrange(n**2)]
# taken = ["F"*n]*(n**2)
taken = ["F"*n for i in xrange(n**2)]
count = 0
sum = 0
for i in xrange(n):
for j in xrange(n):
if i==j:
p[count] = int(earning[i][j]) - value[i]
else:
p[count] = int(earning[i][j]) - (value[i] + value[j])
if p[count] >= 0:
sum += p[count]
taken[i] = taken[i][:j] + 'T' + taken[i][j+1:]
count+=1
# print taken
for i in xrange(n):
for j in xrange(n):
if i>j and taken[i][i] == 'F' and taken[i][j] == 'F' and \
taken [j][j] == 'F':
sum -= int(earning[i][j])
print sum
e = EmployManager()
print e.maximumEarnings([1, 1], ["02", "20"])
print e.maximumEarnings([2, 2], ["01", "10"])
print e.maximumEarnings([1, 2, 3, 4], ["0121", "1021", "2201", "1110"])
print e.maximumEarnings([2, 2, 0, 1, 4, 0, 1, 0, 0, 4], ["0100451253", \
"1010518123", "0102989242", "0020093171", "4590045480", "5189400676", \
"1893500826", "2121468008", "5247872007", "3321066870"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment