[PYTHON] Brown coder tried to solve Panasonic Contest 2020A ~ C

Introduction

Panasonic Programming Contest 2020 3 Complete (Python3 95:30 8WA) I will post the solution of A ~ C.

Click here for the link for Panasonic Programming Contest 2020 https://atcoder.jp/contests/panasonic2020

table of contents

A-Kth Term

Problem statement

Output the Kth term of the following sequence of length 32.

1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_a

I think that you should put this sequence in the list and output the Kth input.

Submission code

main.py


k = int(input())
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(x[k-1])

B-Bishop

Problem statement

There are vertical H-mass and horizontal W-mass boards. A bishop piece is placed in the square in the upper left corner of this board. How many squares can you reach by repeating the movement of 0 or more pieces as you like? For example, when the frame is in the figure, the place where you can move at one time is the red square. https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b

I can't understand at all even if I glance at the problem statement. So, if you look at the figures of Input Example 1 and Input Example 2, you will notice that the colored cells are the numbers obtained by rounding up the number of cells hw / 2.

However, when h = 1 or w = 1 as shown in the figure below, the number of squares that are always colored is 1.

Submission code

main.py


import math
h,w = map(int, input().split(' '))
if h == 1 or w == 1:
    print(1)
else:
    res = math.ceil(h*w / 2)
    print(res)

C-Sqrt Inequality

Problem statement

$ \ Sqrt {a} + \ sqrt {b} <\ sqrt {c} $? https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c

Let's write the code as it is with the problem statement.

main.py


import math

a,b,c = map(int, input().split(' '))
if math.sqrt(a) + math.sqrt(b) < math.sqrt(c):
    print('Yes')
else:
    print('No')

If this is the case, WA will appear. Therefore From $ \ sqrt {a} + \ sqrt {b}> 0 $ and $ \ sqrt {c}> 0 $ \sqrt{a}+\sqrt{b}<\sqrt{c} \Rightarrow a+2\sqrt{ab}+b \Rightarrow 4ab < (c-a-b)^2 And transform the formula so that it does not become an infinite decimal. This will prevent the loss of digits. Below is the code that confirmed the difference. Certainly WA will come out.

Addendum: The code below was incorrect and has been fixed. (2020/3/16)

check.py


from math import sqrt as sq
a = 250000000
b = 250000000
c = 10**9
while sq(a) + sq(b) >= sq(c):
    a += 1
    b -= 1
    print(a,b)
    print(4*a*b, (c-a-b)**2)
    print(sq(a)+sq(b)<sq(c))
    print(4*a*b < (c-a-b)**2)
250000001 249999999
249999999999999996 250000000000000000
False
True
250000002 249999998
249999999999999984 250000000000000000
False
True
250000003 249999997
249999999999999964 250000000000000000
False
True
250000004 249999996
249999999999999936 250000000000000000
False
True
250000005 249999995
249999999999999900 250000000000000000
False
True
250000006 249999994
249999999999999856 250000000000000000
False
True
250000007 249999993
249999999999999804 250000000000000000
True
True

Submission code

main.py


import math

a,b,c = map(int, input().split(' '))
x = 4 * a * b
y = c - a -b
if y <= 0:
    print('No')
elif  x < y**2:
    print('Yes')
else:
    print('No')

It can also be c-a-b <0.

Recommended Posts

Brown coder tried to solve Panasonic Contest 2020A ~ C
[Professional competition] I tried At Coder Beginner Contest 175 (A ~ C)
I wanted to solve the Panasonic Programming Contest 2020 with Python
I tried to solve a combination optimization problem with Qiskit
Solve ABC163 A ~ C with Python
To add a C module to MicroPython ...
Solve ABC168 A ~ C with Python
[Python] Now a brown coder ~ [AtCoder]
Solve ABC036 A ~ C in Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve ABC037 A ~ C in Python
I tried to create a linebot (implementation)
Solve ABC175 A, B, C in Python
I tried to create a linebot (preparation)
Today's AtCoder ~ The Road to the Brown Coder ~
I tried to let optuna solve Sudoku
I tried to make a Web API
I tried to solve TSP with QAOA
AtCoder Green tried to solve with Go
I tried to build a super-resolution method / ESPCN
I tried to build a super-resolution method / SRCNN ①
I wanted to solve NOMURA Contest 2020 with Python
Solve A ~ D of yuki coder 247 with python
I tried to generate a random character string
I tried adding a Python3 module in C
I tried to build a super-resolution method / SRCNN ③
I tried to build a super-resolution method / SRCNN ②
I tried to make a ○ ✕ game using TensorFlow
[Keras] I tried to solve a donut-type region classification problem by machine learning [Study]
AtCoder Beginner Contest 177 Problem C I tried to find out why it was wrong