Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- 0 5 8 10
- 0 1 7
- -> 1
- 1 2
- 4 0 5 8 10
- 3 0 1 7
- -> 1
- 1
- 0 999 1001 2000
- -> 3
- 3
- 0 42
- -> 0
- """
- Slow and huge, but useful for checking smaller inputs.
- input: m, followed by n lines of start and stop times, all servers are turned off in the beginning, all numbers fit inside 32bit signed integers, counts are optional
- output: number of nines of uptime
- example:
- 1
- 0 5 8 9
- 0 1 7
- parsed:
- 1st node: on 0:5, 7:9
- 2nd node: on 0:1, 6:9
- at least one server is running during:
- 0:5, 7:9
- known time interval: 0:9, only timestep 6 is down, so 90% uptime during the part we can see.
- output:
- 1
- """
- import sys
- def rangeify(l):
- res = []
- for i in range(0, len(l), 2):
- res += range(l[i], l[i + 1] + 1)
- return res
- def parse():
- m = input()
- lines = [map(int, x.split()) for x in sys.stdin.read().split("n")[:-1]]
- if not lines:
- return [], m
- top = max(map(max, lines))
- nlines = [x + [top] if len(x) % 2 else x for x in lines]
- n2lines = map(rangeify, nlines)
- return n2lines, m
- def flatten(ls):
- res = []
- for l in ls:
- res += l
- return sorted(res)
- def join(ups):
- res = {}
- for up in ups:
- if up not in res:
- res[up] = 0
- res[up] += 1
- return res
- def bin(ups, m):
- res = []
- for up in range(max(ups)+1):
- res += [up in ups and ups[up] >= m]
- return res
- def nines(a):
- s = ("%.15f" % a)[2:]
- s2 = s.lstrip("9")
- return len(s) - len(s2)
- def solve(l, m):
- if len(l) < m:
- return nines(0)
- b = bin(join(flatten(l)), m)
- return nines(sum(b) / float(len(b)))
- print solve(*parse())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement