Added wrong solution to J
This commit is contained in:
parent
6c0a8a20d2
commit
6f4006e49a
2 changed files with 97 additions and 0 deletions
95
circular_dna.py
Normal file
95
circular_dna.py
Normal file
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
class Gene:
|
||||
def __init__(self, s):
|
||||
self.isStart = s[0] == 's'
|
||||
self.n = int(s[1:])
|
||||
|
||||
def __str__(self):
|
||||
if self.isStart:
|
||||
return "<" + str(self.n)
|
||||
else:
|
||||
return str(self.n) + ">"
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
def is_start_end(g, h):
|
||||
return g.isStart and not h.isStart and g.n == h.n
|
||||
|
||||
def overlaps(a, b):
|
||||
return a[start]
|
||||
|
||||
def count_genes(G):
|
||||
C = {}
|
||||
mC = {}
|
||||
FS = {}
|
||||
S = {}
|
||||
E = {}
|
||||
for i in range(len(G)):
|
||||
e = G[i].n
|
||||
if not e in C:
|
||||
C[e] = 0
|
||||
mC[e] = 0
|
||||
S[e] = i if G[i].isStart else None
|
||||
E[e] = None
|
||||
FS[e] = False
|
||||
|
||||
if G[i].isStart:
|
||||
C[e] += 1
|
||||
|
||||
if FS[e]:
|
||||
FS[e] = False
|
||||
S[e] = i
|
||||
else:
|
||||
C[e] -= 1
|
||||
|
||||
if C[e] < mC[e]:
|
||||
mC[e] = C[e]
|
||||
E[e] = i
|
||||
FS[e] = True
|
||||
|
||||
|
||||
i = 0
|
||||
print(C)
|
||||
print(S, E)
|
||||
|
||||
I = []
|
||||
CI = [0]
|
||||
for key in C:
|
||||
if C[key] == 0:
|
||||
I.append((S[key], +1))
|
||||
I.append((E[key], -1))
|
||||
if I[0][0] >= S[key] or I[0][0] <= E[key]:
|
||||
CI[0] += 1
|
||||
|
||||
if len(I) == 0:
|
||||
return (0, 0)
|
||||
|
||||
last = CI[0]
|
||||
for i in range(1, len(I)):
|
||||
if I[i][1] == +1:
|
||||
last = last + 1
|
||||
CI.append(last)
|
||||
else:
|
||||
last = last - 1
|
||||
CI.append(last + 1)
|
||||
|
||||
m = CI[0]
|
||||
p = I[0][0]
|
||||
for i in range(len(CI)):
|
||||
if CI[i] > m:
|
||||
m = CI[i]
|
||||
p = I[i][0]
|
||||
|
||||
return (p, m)
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(input())
|
||||
genes = input().split()
|
||||
for i in range(len(genes)):
|
||||
genes[i] = Gene(genes[i])
|
||||
start, number = count_genes(genes)
|
||||
print(str(start) + " " + str(number))
|
||||
|
||||
|
2
circular_dna.txt
Normal file
2
circular_dna.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
9
|
||||
e1 e1 s1 e2 s1 s2 e42 e1 s1
|
Reference in a new issue