Ant book in python: page 43 Interval scheduling


# coding: utf-8
import numpy as np

n = int(raw_input())
start = raw_input()
end = raw_input()
data_s = np.array([],dtype=int)
data_e = np.array([],dtype=int)
line = ""
for i in start:
    if i != " ":
        line += i
        # print line
    if i == " ":
        data_s = np.append(data_s, int(line))
        line = ""
data_s = np.append(data_s, int(line))

line = ""
for i in end:
    if i != " ":
        line += i
        # print line
    if i == " ":
        data_e = np.append(data_e, int(line))
        line = ""
data_e = np.append(data_e, int(line))


########################Preprocessing up to here##################

now = -1
history_e = np.array([],dtype=int)
history_s = np.array([],dtype=int)
while(1):
    data_e = data_e[np.where(data_s>now)]
    data_s = data_s[np.where(data_s>now)]
    ind= np.argmin(data_e[np.where(data_s>now)])
    now = data_e[ind]
    history_e = np.append(history_e, data_e[ind])
    history_s = np.append(history_s,data_s[ind])

    if now > data_s.max() or len(data_s) == 0:
        break

print history_s
print history_e
print len(history_e)


numpy request

Recommended Posts

Ant book in python: page 43 Interval scheduling
Ant book in python: page 42 coin problem
Ant book in python: page 49 Fence Repair
Ant book in python: page 47 Saruman's Army (POJ 3069)
Ant book in python: Sec. 2-5 Graph
Ant book in python: page 45 Dictionary order minimum problem (POJ3617)
Ant book in python: Priority queue self-implementation
Ant book in python: Sec. 2-4, data structures
Ant book in python: Sec.2-5 Dijkstra's algorithm
Ant book in python: Sec. 2-5 Graph (preparation)
[Python] Interval scheduling ABC103D
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
Interval scheduling learning memo ~ by python ~
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 ~)
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
SendKeys in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Create a new page in confluence with Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Use a custom error page in python / tornado
Constant in python
nCr 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
Solve "AtCoder version! Ant book (beginner)" with Python!
LiNGAM in Python
Flatten in python
flatten in python
Make each PowerPoint page an image file in Python