Competitive programming diary python 20201213

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

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
Programming in python
python challenge diary ①
Competitive programming with python Local environment settings
[Competitive programming] [Python3] Required knowledge, for myself
I made a competitive programming glossary with Python
I tried competitive programming
Competitive Pro Template (Python)
Python programming with Atom
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
GUI programming in Python using Appjar
[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
Tips you should know when programming competitive programming with Python2 (useful library)
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
Memorandum / memo about programming learning / competitive programming site
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)