コード例 #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
    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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)