Re: Competitive Programming Life Starting from Zero Chapter 1.2 "Python of Tears"

Second enemy

This time we will solve the B problem, which is more difficult than last time! !! Then, the problem is right away! !! ce1c5b58d8be6c42b4e39bd7d61f140b.png

... what's this I think the difficulty level has been raised too much at once ... For the time being, I will draw a diagram and organize what I should ask for. image0.jpeg

Indeed, looking at this figure, which seems to draw something that even this elementary school student is still good at, the answer to this question is the number of L's plus the first one. It was surprisingly easy! !! Then, I immediately wrote it in C ++ ...

Python "(´ ・ ω ・`) "

OT "What's wrong with Python !?"

Python "Don't I use it anymore? (´ ・ ω ・)"

OT "Because Python, I don't have the skills to write code with you ... I don't ....."

Python "Then I don't need a child? (´ ° ̥̥̥̥̥̥̥̥ω ° ̥̥̥̥̥̥̥̥ `)"

OT "Don't make such a sad face Paiso Oh oh oh oh"

...

...

... Yes, so this time I'll write the code in Python.


N, X = map(int, input().split())
L = list(map(int, input().split()))
distance = 0
bounds = 1

For the time being, declare all the variables to use! !!

N, X, L are described with reference to the comments received last time, and if you can clear even here, it should be somehow! !! bounds is the number of times the ball bounces, and the sentence with coordinate D0 is entered from the beginning. distance is the distance the ball has bounced.


for i in range(n): 
    distance += l[i]
    if distance <= x:
      bounds += 1
    else:
      break
print(bounds)

Make sure that the bounds are added until the distance exceeds X in this iterative statement. I managed to get AC! !!

Finally

This time I solved it earlier than last time, but the power of the previous comment was quite strong. Thank you for commenting m (_ _) m With this, the day to see Python's crying face will not come anymore ... I have an unreasonable feeling from Problem C ...

Thank you for reading.

Recommended Posts

Re: Competitive Programming Life Starting from Zero Chapter 1.2 "Python of Tears"
Re: Competitive Programming Life Starting from Zero Chapter 1.3 "Sedo Tea"
[Tweepy] Re: Twitter Bot development life starting from zero # 1 [python]
"Python AI programming" starting from 0 for windows
Re: Competitive programming life starting from zero In order for beginners to get as high a performance as possible ~ ABC154 ~ 156 with impressions ~
Python explosive environment construction starting from zero (Mac)
Let Code Table of Contents Starting from Zero
[Python] Django Source Code Reading View Starting from Zero ①
Competitive programming diary python 20201220
Competitive programming with python
Code of "Programming picture book starting from 10 years old"
Competitive programming diary python
[For beginners of competitive pros] Three input methods to remember when starting competitive programming in Python
Let Code Day 44 "543. Diameter of Binary Tree" starting from zero
[For beginners] Re: Genetic algorithm starting from zero [Artificial intelligence]
Let Code Day87 Starting from Zero "1512. Number of Good Pairs"
ChIP-seq analysis starting from zero
Python Competitive Programming Site Summary
Story of trying competitive programming 2
Let Code Day56 Starting from Zero "5453. Running Sum of 1d Array"
Let Code Day7 starting from zero "104. Maximum Depth of Binary Tree"
Re: Life in Heroku starting from scratch with Flask ~ PhantomJS to Heroku ~
[Python of Hikari-] Chapter 05-03 Control syntax (for statement-extracting elements from list-)
Let Code Day92 Starting from Zero "4. Median of Two Sorted Arrays"
Input / output method of values from standard input in competitive programming, etc.
Let Code Day 35 "160. Intersection of Two Linked Lists" Starting from Zero
Deep Learning / Deep Learning from Zero 2 Chapter 4 Memo
Python3 standard input for competitive programming
Deep Learning / Deep Learning from Zero Chapter 3 Memo
Competitive programming, coding test template: Python3
[Python of Hikari-] Chapter 09-03 Class (inheritance)
Deep Learning / Deep Learning from Zero 2 Chapter 5 Memo
[Python] [Table of Contents Links] Python Programming
Existence from the viewpoint of Python
Code wars kata starting from zero
Life game with Python! (Conway's Game of Life)
Deep Learning / Deep Learning from Zero 2 Chapter 7 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 8 Memo
Deep Learning / Deep Learning from Zero Chapter 5 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 3 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 6 Memo
Re: Heroku life begin with Flask from zero - Environment and Hello world -
Rehabilitation of Python and NLP skills starting with "100 Language Processing Knock 2015" (Chapter 1)
Script of "Programming book starting from elementary and junior high school students"
Python vs Ruby "Deep Learning from scratch" Chapter 4 Implementation of loss function
Let Code Day 11 Starting from Zero "1315. Sum of Nodes with Even-Valued Grandparent"
Let Code Day6 Starting from Zero "1342. Number of Steps to Reduce a Number to Zero"