[PYTHON] Code that I wish I had remembered when I participated in AtCoder for the first time (Reflection 1 for the next time)

March 28, 2020. I participated in AtCoder for the first time.

Participated contest AtCoder Beginner Contest 160 Solve 3 questions A to C and time out with D. I was disappointed that I couldn't do it more than I expected As a review, I will put together the code that I wish I had done quickly.

A collection of codes that you want to be able to write immediately

When multiple numbers are input to the standard input of one line

temp=input()
A=temp.split(" ")
A=[int(i) for i in A]

Let the list A of the entered numbers be cap1.PNG

Add values to the empty list in a loop

N=5
L=list()

for i in range(N):
  L.append(i)

print(L)

cap2.PNG

Returns the maximum value in the list and its index

Before that···

Random number list generation
import random
random.seed(0)

L=[random.randint(0, 100) for i in range(5)]
print(L)

cap3.PNG

Maximum index

#Maximum value
print(max(L))

#index
maxind=L.index(max(L))
print(maxind)

cap4.PNG

Two-dimensional array initialization

#5 rows x 4 columns
D = [[0] * 4 for i in [1] * 5]
print(D)

#Substitute 1 in the 3rd row and 4th column
D[2][3]=1
print(D)

cap5.PNG

Finally

Let's complete Problem D, which was in the process of being implemented

・ Undirected graph ・ BFS (breadth-first search) Let's find out about the keywords of.

2020/4/1 postscript

I tried to make the program that I had made halfway to the end, but it became quite complicated, so I'm sorry. I will study algorithms obediently. ↓ ↓ For studying graph structure, I made a graph class myself and drew it. Create your own graph structure class and its drawing with python

Recommended Posts

Code that I wish I had remembered when I participated in AtCoder for the first time (Reflection 1 for the next time)
The story that had nothing to do with partitions when I did disk backup with dd for the first time
After attending school, I participated in SIGNATE's BEGINNER limited competition for the first time.
I tried tensorflow for the first time
MongoDB for the first time in Python
Impressions and memorandums when working with VS code for the first time
For the first time in Numpy, I will update it from time to time
A useful note when using Python for the first time in a while
I tried python programming for the first time.
I tried Mind Meld for the first time
Looking back on the machine learning competition that I worked on for the first time
What I got into Python for the first time
I tried Python on Mac for the first time.
Register a task in cron for the first time
I tried python on heroku for the first time
For the first time, I learned about Unix (Linux).
AI Gaming I tried it for the first time
Summary of stumbling blocks in Django for the first time
I tried the Google Cloud Vision API for the first time
Kaggle for the first time (kaggle ①)
Kaguru for the first time
I participated in AtCoder (ABC158)
What I learned by writing a Python Pull Request for the first time in my life
Differences C # engineers felt when learning python for the first time
I participated in the ISUCON10 qualifying!
[For self-learning] Go2 for the first time
See python for the first time
Start Django for the first time
I participated in AtCoder (ABC169 edition)
I tried logistic regression analysis for the first time using Titanic data
Until you win the silver medal (top 3%) in the competition you participated in within a month for the first time in data science!
I wrote the code for Gibbs sampling
Let's try Linux for the first time
I stumbled on the character code when converting CSV to JSON in Python
What I did when I got stuck in the time limit with lambda python
Let's display a simple template that is ideal for Django for the first time
GTUG Girls + PyLadiesTokyo Meetup I went to machine learning for the first time
It's okay to participate for the first time! A hackathon starter kit that you want to prepare "before" participating in the hackathon!
A story that I was very convinced when I wrote the code for the Monty Hall problem and calculated the winning percentage