Daily AtCoder # 44 in Python

Introduction

Last time Solve 5 Boot camp problems

#44 ABC056-C

** Thoughts ** The sum of non-negative integers up to i is $ \ frac {1} {2} n (n + 1) $}}. This sum becomes $ X $ when $ \ frac {1} {2} n (n + 1) = X $, and when solving for $ n $, $ n = \ frac {-1 \ pm { It becomes \ sqrt {8X + 1}}} {2} $. Adding the ceil symbol to the solution of this equation yields $ \ lceil \ frac {-1 \ pm {\ sqrt {8X + 1}}} {2} \ rceil $. This is the answer.

import math
x = int(input())

f = (-1+math.sqrt(8*x+1)) / 2
print(math.ceil(f))

ABC066-C

** Thoughts ** Since it will die if it is reversed every time it is operated, bool manages whether it is reversed. We use deque because we only access the left and right sides of the data. All you have to do is implement the operation

from collections import deque
n = int(input())
a = list(input().split())

b = deque([])
r = False
for i in range(n):
    if r:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    r = not r

if r:
    b = reversed(b)
ans = ' '.join(b)
print(ans)

Similar title

ARC069-C

** Thoughts ** First, consider how many sccs can be created without synthesizing c into s. The scc that can be created without synthesizing c into s is $ min (N, M // 2) $. Next, let's consider the case of compositing. When combined, two cs become one s, so if you try to make s from c, you need four cs. All you have to do is implement it.

n, m = map(int,input().split())

if m - 2 * n >= 0: #Whether scc can be made without synthesizing
    ans = n + (m-2*n)//4
    print(ans)
else:
    print(m//2)

ABC130-C

** Thoughts ** If the point to divide is in the center, there are innumerable division methods. Also, the smaller area when divided is half of the total area.

w, h, x, y = map(int,input().split())

s = w * h / 2
if 2*x == w and 2*y == h:
    print(s,1)
else:
    print(s,0)

ARC081-C

** Thoughts ** Counting the $ A_i $ element will probably TLE, so we'll count it in a different way. It is implemented by sorting and counting by value delimiter. If there are 4 or more longest sides, the square that can be made on those sides will be the maximum. Otherwise, it will be a rectangle with two first sides and two second sides.

n = int(input())
a = list(map(int,input().split()))

a.sort(reverse=True)
c = 0
v = []
for i in range(n-1):
    if a[i] != a[i+1]:
        c += 1
        if c >= 2: #Append only when there are two or more sides
            v.append([a[i],c])
        c = 0
    else:
        c += 1
if a.count(a[-1]) >=2:
    v.append([a[-1],a.count(a[-1])])
if len(v) == 0: #If v is empty, you can't make a rectangle
    print(0)
elif v[0][1] >= 4: #Become a square
    print(v[0][0]**2)
elif len(v) >= 2: #Rectangle
    print(v[0][0]*v[1][0])

Summary

This is enough to solve. see you,

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 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 # 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 # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 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 ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda