Exemple #1
0
    def __transform(self, grads_cart, coords, logfilename):
        """Transforms the gradients from the cartesian coordinate system to the
        coordinate system of the optimisation."""

        transform_matrix = self.coordsys_trans_matrix(coords)
        # not with metric because only inequality, only warning about trend
        if numpy.linalg.norm(transform_matrix) > 10:
            lg.warning(common.line() +
                       "Enormous coordinate system derivatives" +
                       common.line())
            lg.warning(logfilename + ": largest elts of trans matrix: " +
                       str(common.vecmaxs(abs(transform_matrix))))

        # energy gradients in optimisation coordinates
        # Gaussian returns forces, not gradients
        """print "transform_matrix"
        print transform_matrix
        print transform_matrix.shape
        print "grads_cart"
        print grads_cart
        print grads_cart.shape"""

        grads_opt = -numpy.dot(transform_matrix, grads_cart)
        # not with metric because only inequality, only warning about trend
        if numpy.linalg.norm(grads_opt) > 10 or numpy.linalg.norm(
                grads_cart) > 10:
            lg.warning(common.line() + "Enormous gradients" + common.line())
            lg.warning(logfilename + ": Largest ZMat gradients: " +
                       str(common.vecmaxs(abs(grads_opt))))
            lg.warning(logfilename + ": Largest Cartesian gradients: " +
                       str(common.vecmaxs(abs(grads_cart))))
            lg.warning(logfilename + ": Largest elts of trans matrix: " +
                       str(common.vecmaxs(abs(transform_matrix))))

        return grads_opt
Exemple #2
0
    def __transform(self, grads_cart, coords, logfilename):
        """Transforms the gradients from the cartesian coordinate system to the
        coordinate system of the optimisation."""

        transform_matrix = self.coordsys_trans_matrix(coords)
        # not with metric because only inequality, only warning about trend
        if numpy.linalg.norm(transform_matrix) > 10:
            lg.warning(common.line() + "Enormous coordinate system derivatives" + common.line())
            lg.warning(logfilename + ": largest elts of trans matrix: " + str(common.vecmaxs(abs(transform_matrix))))

        # energy gradients in optimisation coordinates
        # Gaussian returns forces, not gradients
        """print "transform_matrix"
        print transform_matrix
        print transform_matrix.shape
        print "grads_cart"
        print grads_cart
        print grads_cart.shape"""

        grads_opt = -numpy.dot(transform_matrix, grads_cart)
        # not with metric because only inequality, only warning about trend
        if numpy.linalg.norm(grads_opt) > 10 or numpy.linalg.norm(grads_cart) > 10:
            lg.warning(common.line() + "Enormous gradients" + common.line())
            lg.warning(logfilename + ": Largest ZMat gradients: " + str(common.vecmaxs(abs(grads_opt))))
            lg.warning(logfilename + ": Largest Cartesian gradients: " + str(common.vecmaxs(abs(grads_cart))))
            lg.warning(logfilename + ": Largest elts of trans matrix: " + str(common.vecmaxs(abs(transform_matrix))))

        return grads_opt
Exemple #3
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
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
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)
Exemple #7
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"
Exemple #8
0
1 ≤ F ≤ 4.
1 ≤ X ≤ 2000.

Large dataset

1 ≤ C ≤ 10000.
1 ≤ F ≤ 100.
1 ≤ X ≤ 100000.
"""


def cookie_time(C, F, X):
    rate = 2
    time = 0
    end = float("inf")
    while True:
        e = time + X / rate
        if e < end:
            end = e
        else:
            return end
        time += C / rate
        rate += F


T = ni()
nl()
for I in range(T):
    C, F, X = line(float)
    print("Case #%s:" % (I + 1), cookie_time(C, F, X))
Exemple #9
0
"""

english = """
aoz
our language is impossible to understand
there are twenty six factorial possibilities
so it is okay if you want to just give up
q
"""

googlerese = """
yeq
ejp mysljylc kd kxveddknmc re jsicpdrysi
rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd
de kr kd eoya kw aej tysr re ujdr lkgc jv
z
"""

assert len(set(googlerese)) == 28

from string import maketrans
trans = maketrans(googlerese, english)

T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1),
    for s in line():
        print s.translate(trans),
    print
Exemple #10
0
__copyright__ = "Copyright © 2011–2012 - Renaud Blanch"
__licence__ = "GPLv3 [http://www.gnu.org/licenses/gpl.html]"

from common import nt, ni, nl, line
"""
Recycled Numbers
"""

_r = {}
for n in xrange(2000000):
    sn = str(n)
    l = len(sn)
    ms = set(int(sn[i:] + sn[:i]) for i in range(1, l))
    ms = [m for m in ms if n < m]
    _r[n] = ms


def recycled(A, B):
    r = 0
    for n in range(A, B):
        r += sum(m <= B for m in _r[n])
    return r


T = ni()
nl()
for X in xrange(T):
    print "Case #%s:" % (X + 1),
    A, B = line(int)
    print recycled(A, B)
Exemple #11
0
    for line in zip(*board):
        yield line


def diagonals(board):
    yield [board[i][i] for i in range(4)]
    yield [board[i][3 - i] for i in range(4)]


def status(board):
    not_completed = False
    for quadruplets in [lines, columns, diagonals]:
        for quadruplet in quadruplets(board):
            not_completed |= "." in quadruplet
            P = four(*quadruplet)
            if P:
                return "%s won" % P

    if not_completed:
        return "Game has not completed"
    else:
        return "Draw"


T = ni()
for X in xrange(T):
    nl()
    print "Case #%s:" % (X + 1),
    board = [list(*line()), list(*line()), list(*line()), list(*line())]
    print status(board)