예제 #1
0
def solve(case_index):
    n = read_int()
    k = read_int()
    next_line()

    cakes = [

    ]

    for i in xrange(n):
        cakes.append({
            "r": float(read_int()),
            "h": float(read_int()),
        })

    options = []

    for i in xrange(n):
        lead = cakes[i]
        # Test pancake i as first
        chosen = [lead] + sorted((cake for cake in cakes if cake["r"] <= lead["r"] and cake is not lead), key=lambda cake: cake["h"] * cake["r"], reverse=True)[:k - 1]

        if len(chosen) < k:
            continue

        options.append(calc_area_for_stack(chosen))

    return "{:.08f}".format(max(options) * math.pi)
예제 #2
0
def solve_small1(case_index):
    n = read_int()
    k = read_int()

    assert k == n
    next_line()

    u = read_float()
    next_line()

    p = []

    for i in xrange(n):
        p.append(read_float())

    def try_val(val):
        cost = sum(val - i for i in p if i <= val)
        return cost <= u

    start = 0.0
    end = 1.0
    mid = (end + start) / 2

    #    while (end - start) >= 10 ** -7:
    for i in xrange(1000):
        mid = (end + start) / 2

        if try_val(mid):
            start = mid
        else:
            end = mid

        # print ">>>>", start, end

    print ">>>", end, start
    newp = [max(i, start) for i in p]
    print newp

    #prob = 1 - reduce(lambda x, y: x * y, [1.0 - i for i in newp], 1.0)
    prob = reduce(lambda x, y: x * y, [i for i in newp], 1.0)
    return "{:07f}".format(prob)
예제 #3
0
def solve(case_index):
    print case_index
    d = Fraction(read_int(), 1)
    n = read_int()
    next_line()

    k = []
    s = []

    for i in xrange(n):
        k.append(Fraction(read_int(), 1))
        s.append(Fraction(read_int(), 1))
        next_line()

    def try_speed(test_speed):
        for i in xrange(n):
            if s[i] >= test_speed:
                continue
            if k[i] >= d:
                continue
            t = k[i] / (test_speed - s[i])
            if t * test_speed < d:
                return False
        return True

    speed_min = Fraction(0, 1)
    t_min = min(Fraction((d - k[i]), s[i]) for i in xrange(n) if k[i] <= d)
    speed_max = max(d / t_min, 10)

    TRESH = 10**(-7)

    while speed_max - speed_min > TRESH:
        cur_speed = (speed_min + speed_max) / 2
        if try_speed(cur_speed):
            speed_min = cur_speed
        else:
            speed_max = cur_speed
    # cur_speed = 10

    return "{:.6f}".format(float(cur_speed))
예제 #4
0
def solve_small(case_index):
    n = read_int()

    r = read_int()
    o = read_int()
    y = read_int()
    g = read_int()
    b = read_int()
    v = read_int()

    assert o == 0
    assert v == 0
    assert g == 0

    colors = OrderedDict([
        ("R", r),
        ("O", o),
        ("Y", y),
        ("G", g),
        ("B", b),
        ("V", v),
    ])

    if r > y + b or y > r + b or b > y + r:
        return "IMPOSSIBLE"

    ret = ""
    forbidden = None

    for i in xrange(n):
        temp_colors = OrderedDict(colors)

        if forbidden is not None:
            temp_colors.pop(forbidden)

        next_col = max(temp_colors.items(), key=lambda x: x[1])[0]
        colors[next_col] -= 1
        forbidden = next_col
        ret += next_col

    print ret

    for i in xrange(1000):
        if is_legal(ret):
            break
        l = list(ret[-5:])
        random.shuffle(l)
        ret = ret[:-5] + "".join(l)

    if not is_legal(ret):
        raise Exception("Not legal!!")

    return ret
예제 #5
0
def solve_small(case_index):
    n = read_int()
    q = read_int()
    next_line()

    print "N:", n
    assert q == 1

    e = []
    s = []

    for i in xrange(n):
        e.append(float(read_int()))
        s.append(float(read_int()))
        next_line()

    d = []

    for i in xrange(n):
        cur = []
        for j in xrange(n):
            cur.append(float(read_int()))
        next_line()
        d.append(cur)

    u = []
    v = []

    for i in xrange(q):
        u.append(read_int())
        v.append(read_int())
        next_line()

    assert u[0] == 1, v[0] == n

    g = networkx.DiGraph()

    for i in xrange(1, n + 1):
        g.add_node(i)

    for i in xrange(1, n):
        horse_kms = e[i - 1]
        horse_speed = s[i - 1]

        j = i
        traveled = 0
        while j < n:
            dist_to_next_city = d[j - 1][j]
            print "Dist to next", dist_to_next_city
            traveled += dist_to_next_city
            horse_kms -= dist_to_next_city

            if horse_kms < 0:
                break
            j += 1
            g.add_edge(i, j, {"time": traveled / horse_speed})

    print g.edge
    path_length = networkx.shortest_path_length(g, 1, n, "time")
    # path_length = 0

    return "{:.6f}".format(path_length)