Daily AtCoder # 24 in Python

Introduction

Last time This time, we will solve the solvable problem of this.

#24 ABC045-C 1110diff

** Thoughts ** For the first time, I learned a method called bit full search, so I will use it. Search all for whether to put a symbol between letters.

s = input()

ans = 0
n = len(s) - 1 #The interval is one less than the number of characters
for i in range(2 ** n):
    op = [''] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = '+'
    formula = ''
    for p_n, p_o in zip(s,op+['']):
        formula += (p_n+p_o)
    ans += eval(formula)

print(ans)

ABC079-C 302diff

** Thoughts ** The difference from the previous problem is that there are two symbols, but they are almost the same. eval calculates a character expression and returns an int.

abcd = input()
n = len(abcd) - 1
for i in range(2 ** n):
    op = ['-'] * n
    for j in range(n):
        if ((i >> j) & 1):
            op[n - j - 1] = '+'
    formula = ''
    for p_n, p_o in zip(abcd, op + ['']):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + '=7')
        break

ARC029 465diff

** Thoughts ** Search all bits depending on which meat grill you use. After that, just update the minimum value.

n = int(input())
t = [int(input()) for _ in range(n)]
ans = 10**9
for i in range(2 ** n):
    niku = ['Left'] * n
    for j in range(n):
        if ((i >> j) & 1):
            niku[n - j - 1] = 'Right'
    wait_time_left = 0
    wait_time_rignt = 0
    for k in range(n):
        if niku[k] == 'Left':
            wait_time_left += t[k]
        if niku[k] == 'Right':
            wait_time_rignt += t[k]
    wait_time = max(wait_time_left,wait_time_rignt)
    ans = min(ans,wait_time)
print(ans)

Problems that could not be done

ABC104-C I couldn't write the processing of the problem to be solved halfway.

d, g = map(int,input().split())
pc = [list(map(int,input().split())) for _ in range(d)]
n = len(pc)
ans = 10**9
for i in range(2 ** n):
    cost = 0
    score = 0
    check = [False] * n

    for j in range(n):
        if ((i >> j) & 1):
            check[n - j - 1] = True

    for k in range(n):
        if check[k]:
            for l in range(pc[k][0]):
                cost += 1
                score += 100 * (k+1)
                if l == pc[k][0]-1:
                    score += pc[k][1]
                if score >= g:
                    ans = min(ans,cost)
print(ans)

ABC002-C When I was thinking about whether to include 12 members in the faction, I couldn't write a code to confirm each other.

Summary

difficult. It's fun to learn new things, but if you can't solve it, it's meaningless, so solve past questions so that you can take root. see you

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python