Daily AtCoder # 22 in Python

Introduction

Last time I'm doing a recent C today

#22

** Thoughts ** ABC160-C I was trying to think about all of $ N! * N $ during the contest, but that would be a TLE. Since we will visit all N, there is a section that does not pass one. If you think of it as clockwise or counterclockwise from $ A_i $, it will not pass either left or right. Therefore, the answer is $ A_i $ and the maximum value of the left and right distances. Note that in the case of $ A_N $ → $ A_1 $, it cannot be calculated as it is, so it was calculated separately.

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

cost = max(a[0]+k-a[-1],a[-1]-a[-2])
for i in range(1,n-1):
    cost = max(a[i]-a[i-1],a[i+1]-a[i],cost)
print(k-cost)

ABC159-C Since the volume is maximum when it is a rectangular parallelepiped, just divide it by 3 and cube it.

print((int(input())/3)**3)

ABC158-C Just calculate. When I solved it last time, I was told that I could turn it for more with a margin, so I calculated up to 10000. It is truncated at // 1.

a, b = map(int,input().split())
for i in range(10000):
    if (i * 0.08)//1 == a and (i * 0.1)//1 == b:
        print(i)
        quit()
print(-1)

ABC157-C When I saw the problem, I thought it was easy, but I couldn't. I couldn't even compare it digit by digit with str. As far as I can see the result, it is not possible to divide the case well. Revenge

ABC156-C Since $ N $ is small, the cost is calculated with all integers less than $ N $. Is it minimal near the median?

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

ans = 10**9
for i in range(101):
    cost = 0
    for j in range(n):
        cost += (x[j]-i)**2
    ans = min(ans,cost)
print(ans)

ABC155-C I put $ S $ in collections.Counter and do most_common to find the mode. All you have to do is output

import collections
n = int(input())
s = [str(input()) for _ in range(n)]
s = collections.Counter(s)
s = s.most_common()
c = s[0][1]
ans = []
for i in range(len(s)):
    if s[i][1] == c:
        ans.append(s[i][0])
ans.sort()
for i in ans:
    print(i)

Summary

C is fun. 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 # 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 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