https://atcoder.jp/contests/abc185/
Just output the smallest of the four numbers given
print(min(list(map(int, input().split()))))
The code is dirty, but it is implemented with the idea that it should be judged whether the battery is 0 or less at the time of entering the cafe and at the end I made a mistake at first forgetting that the battery will not exceed its maximum capacity
n, m, t = map(int, input().split())
max_n = n
now = 0
ans = "Yes"
for i in range(m):
a, b = map(int, input().split())
n = n - a + now
if n <= 0:
ans = "No"
break
n = min(n + (b - a), max_n)
now = b
if n - t + now <= 0:
ans = "No"
print(ans)
How to divide when cutting a bow of length L at 11 points? It is a problem that is likely to occur in the examination
Since it is divided so that it has an integer length, the cutting point is L-1. Can you find it with L ―― 1 C 11?
from math import factorial
L = int(input())
print(int(factorial(L - 1) / factorial(L - 12) / factorial(11)))
I thought, but this is no good. When you read the commentary
It should be noted that the value of this fraction itself is 2 ** 63 Less than, but the molecule is The point is that it may not fit in a 64-bit integer type. There are several ways to avoid the overflow.
Is it out because it exceeds the size of int64? .. I didn't have this idea. It seems good to solve the recurrence formula enemy using Pascal's triangle
I tried something like memoization recursion. The function is full of side effects, so it feels bad
from math import factorial
L = int(input())
matrix = [[[] for _ in range(201)] for _ in range(201)]
def pascal(i, j):
if matrix[i][j]:
return matrix[i][j]
if j == 0 or i == j:
return 1
ans = pascal(i-1, j-1) + pascal(i-1, j)
matrix[i][j] = ans
return(pascal(i-1, j-1) + pascal(i-1, j))
print(pascal(L-1, 11))
As for how to make a stamp, it seems that the smallest one among the consecutive number of white squares should be adopted. A stamp with a width of 4 can be filled with a stamp with a width of 5 by using the stamp twice.
n, m = map(int, input().split())
if m == 0:
print(1)
exit()
a = sorted(list(map(int, input().split())))
white = []
for i in range(len(a)):
if i == 0:
white.append(a[i] - 1)
elif i == (len(a) - 1):
white.append(a[i] - a[i-1] -1)
white.append(n - a[i])
else:
white.append(a[i] - a[i-1] -1)
white = list(filter(lambda x: x != 0, white))
if len(white) == 0:
print(0)
exit()
k = min(white)
ans = 0
for l in white:
x = l // k
amari = l % k
if amari != 0:
x += 1
ans += x
print(ans)
It's pretty ad hoc, but I passed
Up to here for this time!
Recommended Posts