Competitive programming diary python 20201220

https://atcoder.jp/contests/abc186/

A - Brick

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

print(n // w)

B - Blocks on Grid

Match to the smallest number of all squares. Since it is an order of about 10 to the 4th power, it seems good to turn the loop honestly

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

blocks = []

for i in range(h):
    blocks += list(map(int, input().split()))
    
min_block = min(blocks)

ans = 0

for a in blocks:
    ans += a - min_block
    
print(ans)

C - Unlucky 7

How many numbers from 1 to N do not contain 7 in either decimal or octal?

Since N is 10 to the 5th power or less, it seems good to check for all numbers below N.

n = int(input())

ans = 0

for a in range(1, n+1):
    ten = str(a)
    eight = format(a, 'o')
    if "7" not in ten and "7" not in eight:
        ans += 1
print(ans)

D - Sum of difference

N Add to this number to get the sum of all the differences. Should I loop for a combination? That would exceed the amount of calculation. If you sort in advance by size, you will not need to calculate the absolute value.

n = int(input())
numbers = sorted(list(map(int, input().split())))

ans = 0
other_sum = sum(numbers)
other_len = len(numbers)

for i, a in enumerate(numbers):
    other_sum -= a
    other_len -= 1
    ans += (other_sum) - a * (other_len)

print(ans)

Recommended Posts

Competitive programming diary python 20201213
Competitive programming diary python 20201220
Competitive programming diary python
Competitive programming with python
Python Competitive Programming Site Summary
Python3 standard input for competitive programming
Competitive programming, coding test template: Python3
Python programming note
python challenge diary ①
[Competitive programming] [Python3] Required knowledge, for myself
I made a competitive programming glossary with Python
I tried competitive programming
3. 3. AI programming with Python
Competitive Pro Template (Python)
Python programming in Excel
LEGO Mindstorms 51515 Python Programming
[Python] Dynamic programming ABC015D
Programming with Python Flask
Tips you should know when programming competitive programming with Python2
Programming with Python and Tkinter
Python Programming Workshop-Super Introductory Vol.3
Python3 programming functions personal summary
Atcoder Acing Programming Contest Python
[Python] Dynamic programming knapsack problem
[Python] Dynamic programming TDPC D
Python web programming article summary
Paiza Python Primer 1 Learn Programming
Python Machine Learning Programming> Keywords
Competitive programming is what (bonus)
Python Programming Workshop-Super Introductory Vol.4
Story of trying competitive programming 2
An introduction to Python Programming
[Python] Competitive template [At Coder]
[Python] Dynamic programming TDPC A
Network programming with Python Scapy
Knowledge you need to know when programming competitive programming with Python2
[Swift / Ruby / Python / Java] Object-oriented programming
GUI programming in Python using Appjar
Functional programming in Python Project Euler 1
[Introduction to Python3 Day 1] Programming and Python
Python
Functional programming in Python Project Euler 3
[Python] [Table of Contents Links] Python Programming
Competitive professional devotion diary 11th-14th days (7 / 5-7 / 8)
[Python] Object-oriented programming learned with Pokemon
Easy Python + OpenCV programming with Canopy
Story of trying competitive programming Part 1
Functional programming in Python Project Euler 2
python documentation reading socket programming HOWTO
Python Programming Workshop-Super Introductory Python Execution Environment
Re: Competitive Programming Life Starting from Zero Chapter 1.2 "Python of Tears"
Tips (input / output) that you should know when programming competitive programming with Python2
Tips (control structure) that you should know when programming competitive programming with Python2
Tips (data structure) that you should know when programming competitive programming with Python2
Competitive professional devotion diary 18th to 19th days (7/12 to 7/13)
Eating and comparing programming languages: Python and Ruby
"Python AI programming" starting from 0 for windows
What kind of programming language is Python?
"Python Machine Learning Programming" Summary Note (Jupyter)
Scientific Programming Petit Tech Collection in Python
Try text mining your diary in Python