Ant book in python: page 47 Saruman's Army (POJ 3069)


# coding: utf-8
N = raw_input()
R = raw_input()
X = raw_input()
N, R, X = map(int, N.split())[0],map(int, R.split())[0],map(int, X.split())


colored_pos = [X[0]]
pos = X[0]
# print X
while(1):
    far = pos
    for (i,x) in enumerate(X):
        if pos + R > x:
            far = x
        else:
            break
    colored_pos.append(far)
    pos = x

    if pos + x > X[-1]:
        break

print colored_pos

I learned split ().

Recommended Posts

Ant book in python: page 47 Saruman's Army (POJ 3069)
Ant book in python: page 42 coin problem
Ant book in python: page 43 Interval scheduling
Ant book in python: page 45 Dictionary order minimum problem (POJ3617)
Ant book in python: Sec. 2-5 Graph
Ant book in python: Priority queue self-implementation
Ant book in python: Sec.2-5 Dijkstra's algorithm
Ant book in python: Sec. 2-5 Graph (preparation)
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Page cache in Python + Flask with Flask-Caching
Ant book with python (chapter3 intermediate edition ~)
Create a new page in confluence with Python
Use a custom error page in python / tornado
Solve "AtCoder version! Ant book (beginner)" with Python!
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Disassemble in Python
Reflection in Python
Constant in python
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Python reference page
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
flatten in python
Make each PowerPoint page an image file in Python
How to add page numbers to PDF files (in Python)
Implemented the algorithm of "Algorithm Picture Book" in Python3 (Heapsort)