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))
** 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)
** 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)
** 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)
** 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])
This is enough to solve. see you,
Recommended Posts