正常运行时间是一个非常重要的指标,正如我们都知道的,所以我们想测量自我们的服务第一次推出以来的正常运行时间。SLA指定一定数量的9的正常运行时间,例如至少99.9%
正常运行时间为3 9,或至少为90%
正常运行时间为1 9,您想知道是否确实遇到了SLA。因为您知道在上周五晚上有人推动生产时,服务已经停止了,而且这基本上是这里的标准实践,因此您认为您的代码没有必要将100%的正常运行时间作为特例处理。
每次服务器停止或启动时,Nagios都会向您发送电子邮件。所讨论的服务具有一定的容错能力,因此只有m
服务器才能在线才能获得该服务。你只是写了一个快速的脚本,从这些电子邮件中提取重要信息。现在是玩得开心的时候了,你也有心情打高尔夫球了。
您的任务是编写一个程序或函数,分析输入,计算出正常运行时间,并打印服务实现的最大整数9。
m
> 0。\n
,后面是EOF
(ctrl+D)。0
开始,结束于单个服务器上一次记录的开始/停止,因为这是我们到目前为止所掌握的全部信息。这可以通过在所有奇数行的末尾添加最大值(每行的最后一个数字)来实现。输出:
输出由一个整数组成;可以保证在事后才能保证的9的最高数量,即3
至少用于99.9%
正常运行时间,或4
用于至少99.99%
正常运行时间。
第一:
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
参考实现:(Python 2)
"""
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())
发布于 2016-05-24 23:39:45
(m,a)=>a.map(b=>b.map(n=>l=n>l?n:l),l=0)|a.map(b=>c.map((_,i)=>{k=b[j]==i;j+=k;n^=k;c[i]+=n|k},j=n=0),c=Array(++l).fill(0))|Math.log10(l/c.filter(n=>n<m).length)
接受表示并发服务器的最小数目的整数和表示每个服务器的开始和停止时间的数组。编辑:现在使用包含范围,因此正确返回第一个示例的1。
发布于 2016-05-25 01:00:56
/`.Omgsm%lf<dTk2.QQeSs.Q`9
在网上试一试。
https://codegolf.stackexchange.com/questions/80563
复制相似问题