示例#1
0
from common import nt, ni, nl, line

keys = 'aoz' + 'ejp mysljylc kd kxveddknmc re jsicpdrysi' + 'rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd' + 'de kr kd eoya kw aej tysr re ujdr lkgc jv' + 'q'
values = 'yeq' + 'our language is impossible to understand' + 'there are twenty six factorial possibilities' + 'so it is okay if you want to just give up' + 'z'

# Generate mapping
mapping = {}
for i,k in enumerate(keys):
    mapping[k] = values[i]
   
n = ni(); nl()
for case in xrange(n):
    text = ' '.join(line())
    text = ''.join([mapping[c] for c in text])
    print "Case #%s:" % (case+1),
    print text
示例#2
0
		a, m = t/3, t % 3
		assert a*3+m == t
		
		if m == 0:
			best = a
			if 0 < best < p:
				best += 1
				S -= 1
		elif m == 1:
			best = a+1
		elif m == 2:
			best = a+1
			if best < p:
				best += 1
				S -= 1			
		if best < p:
			break
		if S < 0:
			break
		i+= 1
	return i

T = ni(); nl()
for X in xrange(T):
	print "Case #%s:" % (X+1),
	N, S, p = ni(), ni(), ni()
	ts = list(line(int))
	assert len(ts) == N
	assert S <= N
	print solve(N, S, p, ts)
示例#3
0
    r = 1.
    yield r
    for p in ps:
        r *= p
        yield r


def opt_strategy(A, B, ps):
    cum_ps = list(products(*ps))
    scores = []
    #	for i in range(A+1): # nb of bsp
    #		p = cum_ps[A-i]
    #		score = p*(B+2*i+1) + (1.-p)*(2*B+2*i+2)
    #		scores.append(score-A)
    scores = [
        B - A + 2 * i + 1 + (1. - cum_ps[A - i]) * (B + 1)
        for i in range(A + 1)
    ]
    scores.append(B + 2)
    return min(scores)


T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1),
    A, B = line(int)
    ps = [p for p in line(float)]
    assert len(ps) == A
    print opt_strategy(A, B, ps)
示例#4
0
from common import nt, ni, nl, line
"""
Lawnmower
"""


def max_line(lawn):
    return [list(u < max(line) for u in line) for line in lawn]


def possible(N, M, lawn):
    lines = max_line(lawn)
    columns = zip(*max_line(zip(*lawn)))
    for i in xrange(N):
        for j in xrange(M):
            if lines[i][j] and columns[i][j]:
                return False
    return True


T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1),
    N, M = ni(), ni()
    nl()
    lawn = [list(line(int)) for _ in xrange(N)]
    assert (len(lawn), len(lawn[0])) == (N, M)
    print "YES" if possible(N, M, lawn) else "NO"
示例#5
0
number on the card. If there are multiple cards the volunteer could have
chosen, y should be "Bad magician!", without the quotes. If there are no
cards consistent with the volunteer's answers, y should be
"Volunteer cheated!", without the quotes. The text needs to be exactly right,
so consider copying/pasting it from here.

Limits

1 ≤ T ≤ 100.
1 ≤ both answers ≤ 4.
Each number from 1 to 16 will appear exactly once in each arrangement.
"""

cards = set(u+1 for u in range(16))

T = ni(); nl()
for X in range(T):
	card = set(cards)
	for _ in range(2):
		l = ni(); nl()
		for i in range(4):
			row = set(line(int))
			if i+1 == l:
				card &= row
	if not card:
		result = "Volunteer cheated!"
	elif len(card) == 1:
		result = card.pop()
	else:
		result = "Bad magician!"
	print("Case #%s:" % (X+1), result)
示例#6
0
"""

from string import lowercase

vowels = "aeiou"
#consonants = set(lowercase) - vowels


def score(s, n):
    s = s.split()
    return 1 if any(len(u) >= n for u in s) else 0


def n_value(name, n):
    l = len(name)
    s = 0
    for v in vowels:
        name = name.replace(v, " ")
    for b in range(l - n + 1):
        for e in range(b + n, l + 1):
            s += score(name[b:e], n)
    return s


T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1),
    name, n = nt(), ni()
    nl()
    print n_value(name, n)
示例#7
0
def solve(nums):

    # Map sum to list of numbers resulting
    sums = {}

    # Loop through all combos
    for c in range(1, len(nums) + 1):
        for combo in itertools.combinations(nums, c):
            s = sum(combo)
            if s in sums:
                print
                print ' '.join([str(n) for n in sums[s]])
                print ' '.join([str(n) for n in combo])
                return
            else:
                sums[s] = combo
    print "Impossible"


T = ni()
nl()
for case in xrange(T):
    print "Case #%s:" % (case + 1),
    N = ni()
    nums = []
    for n in xrange(N):
        nums.append(ni())
    solve(nums)
    nl()
示例#8
0
        return _oowp[key]
    except:
        pass

    sowp, n = 0., 0.
    for j, c in enumerate(scores[i]):
        if c == '.':
            continue
        sowp += owp(j, scores)
        n += 1
    _oowp[key] = oowp = sowp / n
    return oowp


def rpi(i, scores):
    return .25 * wp(scores[i]) + .5 * owp(i, scores) + .25 * oowp(i, scores)


T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1)
    N = ni()
    nl()
    scores = []
    for i in xrange(N):
        scores.append(nt())
        nl()
    for i in xrange(N):
        print rpi(i, scores)
示例#9
0
				if l >= n:
					l, c, r = n, 0, 0
					n *= 10
	

def is_palindrome(p):
	p = str(p)
	l = len(p)
	return all(p[i] == p[l-i-1] for i in range(l/2))

def fair_and_square(A, B):
	a = int(floor(sqrt(A)))
	assert a*a <= A
	Ps = []
	for p in palindromes(a):
		P = p*p
		if B < P:
			break
		if A <= P:
			if is_palindrome(P):
				Ps.append(P)
	return len(Ps)

T = ni(); nl()
for X in xrange(T):
 	print "Case #%s:" % (X+1),
	A, B = ni(), ni()
	nl()
	assert A <= B
	print fair_and_square(A, B)
示例#10
0
def evolve(vendors, dt, D):
	p = -INF
	for i, v in enumerate(vendors):
		if v-dt >= p+D:
			v -= dt
		else:
			v = min(p+D, v+dt)
		p = vendors[i] = v

def minimum(vendors, D):
	t = 0.
	while True:
		d = d_min(vendors)
		if d >= D:
			break
		dt = (D - d)/2.
		t += dt
		evolve(vendors, dt, D)
	return t

T = ni(); nl()
for X in xrange(T):
	print "Case #%s:" % (X+1),
	C, D = ni(), ni(); nl()
	vendors = []
	for _ in xrange(C):
		P, V = ni(), ni(); nl()
		for i in range(V):
			vendors.append(float(P))
	print minimum(vendors, D)