示例#1
0
def converse():
    moves=[]
    line= file.readline().split()
    for i in range(0,string._int(line[0])):
        move=(line[2*i+1],string._int(line[2*i+2]))
        moves.append(move)
    time=0
    opos=1
    bpos=1
    lat=0
    prev='O'
    for move in moves:
        if(move[0]=='O'):
            go=abs(move[1]-opos)
            if(prev!='O'):
                go=max(0,go-lat)
                lat=go+1
            else:
                lat+=go+1
            time+=go+1
            opos=move[1]
            prev='O'
        else:
            go=abs(move[1]-bpos)
            if(prev!='B'):
                go=max(0,go-lat)
                lat=go+1
            else:
                lat+=go+1
            time+=go+1
            bpos=move[1]
            prev='B'
    return time
示例#2
0
def converse():
    mixtures = {}
    opsite = set()
    line = file.readline().split()
    size = string._int(line[0])
    del line[0]
    for i in range(0, size):
        mixture = line[0]
        del line[0]
        mixtures[(mixture[0], mixture[1])] = mixture[2]
        mixtures[(mixture[1], mixture[0])] = mixture[2]
    size = string._int(line[0])
    del line[0]
    for i in range(0, size):
        op = line[0]
        del line[0]
        opsite.add((op[0], op[1]))
        opsite.add((op[1], op[0]))
    del line[0]
    ingreedmentsInside = {}
    result = []
    for move in line[0]:
        if (len(result) == 0):
            result.append(move)
            ingreedmentsInside[move] = 1
        else:
            if (mixtures.has_key((result[-1], move))):
                newKey = mixtures[(result[-1], move)]
                if (ingreedmentsInside[result[-1]] == 1):
                    ingreedmentsInside.pop(result[-1])
                else:
                    ingreedmentsInside[result[-1]] -= 1
                del result[-1]
                result.append(newKey)
                if (ingreedmentsInside.has_key(newKey)):
                    ingreedmentsInside[newKey] += 1
                else:
                    ingreedmentsInside[newKey] = 1
            else:
                result.append(move)
                if (ingreedmentsInside.has_key(move)):
                    ingreedmentsInside[move] += 1
                else:
                    ingreedmentsInside[move] = 1
            for key in ingreedmentsInside.keys():
                if ((key, result[-1]) in opsite):
                    result = []
                    ingreedmentsInside = {}
                    break
    return str(result).replace('\'', '')
def warning (text, level = 1, exit = 0):
    """Use 3 for information, 2 for warning, 1 for error"""
    log_level = string._int(os.getenv("DIKB_LOG_LEVEL"))
    if (log_level >= level):
        sys.stderr.write (" ".join(["DIKB: warning:", text, "\n",]))
        sys.stderr.flush()
        if exit:
            sys.exit (1)
    return
示例#4
0
            if (line[col]=='#'):
                array[row][col]='#'
    
    for row in range(size[0]):
        for col in range(size[1]):
            if (array[row][col]=='#'):
                array[row][col]='/'
                if((row==size[0]-1) or (col==size[1]-1)):
                    print "Impossible"
                    return
                if(not((array[row+1][col]=='#') and (array[row][col+1]=='#') and (array[row+1][col+1]=='#'))):
                    print "Impossible"
                    return
                array[row+1][col]='\\'
                array[row][col+1]='\\'
                array[row+1][col+1]='/'
    for row in range(size[0]):
        line=""
        for col in range(size[1]):
            line+=array[row][col]
        print line
    

                 

file = open('./a2.in')
for i in range(0,string._int(file.readline())):
    print 'Case #%s:' %((i+1))
    converse()

示例#5
0
  # The statuses retrieved are merely counters for each host/service state...
  for line in f.readlines():
    if hst.match(line):
      hosts = Bunch(Up      = string.atoi(string.split(line)[2]),
		    Down    = string.atoi(string.split(line)[4]),
		    Unreach = string.atoi(string.split(line)[6]))
    if srv.match(line):
      servs = Bunch(OK       = string.atoi(string.split(line)[2]),
                   Warning  = string.atoi(string.split(line)[4]),
                   Unknown  = string.atoi(string.split(line)[6]),
                   Critical = string.atoi(string.split(line)[8]))
    if upt.match(line):
      # Resulting format is: Dd HH:MM, where D is number of days.
      uptime = "%s %2.2d:%2.2d" % \
              (string.split(line)[3],
               string._int(string.split(line)[4].strip("h")),
               string._int(string.split(line)[5].strip("m")))
    if age.match(line):
      # Resulting format is: [HH:MM].
      stat_age = "[%2.2d:%2.2d]" % \
                 (string._int(string.split(line)[5].strip("m")),
                  string._int(string.split(line)[6].strip("s")))
  r = os.WEXITSTATUS(f.close() or 0)
  if r != 0: err("nagiostats: error: is nagios running?")
  return Bunch(hosts = hosts, services = servs, uptime = uptime, age = stat_age)

def get_raid_arrays():
  "Retrieve list of active RAID arrays, e.g. [md0, md1, ...]."
  raid_arrays = []
  "Use a regular expression to match the lines we're intrested in."
  expect = re.compile("^ARRAY[ \t]+/dev/md[0-9]+[ \t]+level=raid1")
示例#6
0
def partition2(L, j):
    '''partitions list L into j sublists. The last group may have more elements than previous groups. The result list will have length j.
    Example: print partition2(range(1,8+1),3)
    returns: [[1, 2], [3, 4], [5, 6], [7, 8, 7, 8]]'''
    quotient = len(L) / j
    remainder = len(L) % j
    if remainder == 0:
        return partition(L, quotient)
    result = partition(L, quotient + 1)
    nrm = len(L) % (quotient + 1)
    result = result + [L[-nrm:]]
    return result


for el in cpts:
    chapterNumber = string._int(el[0])
    chapterNumberStr = el[0]
    chapterNumberText = el[1]
    chapterTitle = el[2]
    nextChapterNumberStr = "%03d" % (
        (chapterNumber + numOfChapters + 1) % numOfChapters)  # e.g. '013'

    filename = 'x' + chapterNumberStr + '.html'
    filePath = sourceRoot + '/' + filename

    print 'reading:', filename
    inF = open(filePath, 'rb')
    maintxt = unicode(inF.read(), 'utf-8')
    inF.close()

    maintxt = maintxt.strip()
示例#7
0
def partition2(L,j):
    '''partitions list L into j sublists. The last group may have more elements than previous groups. The result list will have length j.
    Example: print partition2(range(1,8+1),3)
    returns: [[1, 2], [3, 4], [5, 6], [7, 8, 7, 8]]'''
    quotient=len(L)/j
    remainder=len(L)%j
    if remainder==0:
        return partition(L,quotient)
    result = partition(L,quotient+1)
    nrm=len(L)%(quotient+1)
    result = result + [L[-nrm:]]
    return result

for el in cpts:
   chapterNumber=string._int(el[0])
   chapterNumberStr=el[0]
   chapterNumberText=el[1]
   chapterTitle=el[2]
   nextChapterNumberStr = "%03d"%( (chapterNumber+numOfChapters+1)%numOfChapters ) # e.g. '013'

   filename='x' + chapterNumberStr + '.html'
   filePath= sourceRoot + '/' + filename

   print 'reading:', filename
   inF = open(filePath,'rb')
   maintxt=unicode(inF.read(),'utf-8')
   inF.close()

   maintxt=maintxt.strip()
   paragraphs=maintxt.split('\n    ')