본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 94

반응형

Q>

Nicola regularly inspects the local networks for security issues.

(Nicola는 정기적으로 로컬 네트워크에서 보안 문제를 검사합니다.)

He uses a smart and aggressive program which takes control of computers on the network.

(그는 네트워크상의 컴퓨터를 제어하는 ​​똑똑하고 공격적인 프로그램을 사용합니다.)

This program attacks all connected computers simultaneously, then uses the captured computers for further attacks.

(이 프로그램은 연결된 모든 컴퓨터를 동시에 공격 한 다음 캡처 된 컴퓨터를 추가 공격에 사용합니다.)

Nicola started the virus program in the first computer and took note of the time it took to completely capture the network.

(Nicola는 첫 번째 컴퓨터에서 바이러스 프로그램을 시작하고 네트워크를 완전히 캡처하는 데 걸리는 시간을 기록했습니다.)

We can help him improve his process by modeling and improving his inspections.

(우리는 그의 검사를 모델링하고 개선함으로써 자신의 프로세스를 개선 할 수 있도록 도울 수 있습니다.)

We are given information about the connections in the network and the security level for each computer.

(네트워크의 연결 및 각 컴퓨터의 보안 수준에 대한 정보가 제공됩니다.)

Security level is the time (in minutes) that is required for the virus to capture a machine.

(보안 수준은 바이러스가 시스템을 캡처하는 데 필요한 시간 (분)입니다.)

Capture time is not related to the number of infected computers attacking the machine.

(캡처 시간은 컴퓨터를 공격하는 감염된 컴퓨터의 수와는 관련이 없습니다.)

Infection start from the 0th computer (which is already infected).

(이미 감염된 0 번째 컴퓨터에서 감염이 시작됩니다.)

Connections in the network are undirected.

(네트워크의 연결 방향이 바뀌 었습니다.)

Security levels are not equal to zero (except infected).

(보안 수준은 0이 아닙니다 (감염된 경우 제외).)

Information about a network is represented as a matrix NxN size, where N is a number of computers.

(네트워크에 대한 정보는 행렬 NxN 크기로 표시됩니다. 여기서 N은 컴퓨터 수입니다.)

If ith computer connected with jth computer, then matrix[i][j] == matrix[j][i] == 1, else 0.

(i 번째 컴퓨터가 j 번째 컴퓨터와 연결된 경우 matrix [i] [j] == matrix [j] [i] == 1, 그렇지 않으면 0.)

Security levels are placed in the main matrix diagonal, so matrix[i][i] is the security level for the ith computer.

(보안 수준은 주 매트릭스 대각선에 배치되므로 matrix [i] [i]는 i 번째 컴퓨터의 보안 수준입니다.)

You should calculate how much time is required to capture the whole network in minutes.

(몇 분 안에 전체 네트워크를 캡처하는 데 필요한 시간을 계산해야합니다.)

 

Input: Network information as a list of lists with integers.

         (정수로 구성된 목록의 네트워크 정보.)

 

Output: The total time of taken to capture the network as an integer.

            (네트워크를 정수로 캡처하는 데 걸린 총 시간입니다.)

 

Example:

capture([[0, 1, 0, 1, 0, 1],
         [1, 8, 1, 0, 0, 0],
         [0, 1, 2, 0, 0, 1],
         [1, 0, 0, 1, 1, 0],
         [0, 0, 0, 1, 3, 1],
         [1, 0, 1, 0, 1, 2]]) == 8
capture([[0, 1, 0, 1, 0, 1],
         [1, 1, 1, 0, 0, 0],
         [0, 1, 2, 0, 0, 1],
         [1, 0, 0, 1, 1, 0],
         [0, 0, 0, 1, 3, 1],
         [1, 0, 1, 0, 1, 2]]) == 4
capture([[0, 1, 1],
         [1, 9, 1],
         [1, 1, 9]]) == 9

 

How it is used: This concept shows how to model and examine various network configurations.

                     (이 개념은 다양한 네트워크 구성을 모델링하고 검사하는 방법을 보여줍니다.)

                     The idea does not only apply to computer networks however,

                     (이 아이디어는 컴퓨터 네트워크에만 적용되는 것은 아니지만,)

                     it can also be a model for the spread of disease or dissemination of rumors.

                     (질병 확산이나 소문 확산 모델이 될 수도 있습니다.)

 

Precondition:

3 ≤ len(matrix) ≤ 10 matrix[0][0] == 0 all(len(row) == len(matrix[0]) for row in matrix) all(matrix[i][j] == matrix[j][i] for i in range(len(matrix)) for j in range(len(matrix))) all(0 < matrix[i][i] < 10 for i in range(1, len(matrix))) all(0 ≤ matrix[i][j] ≤ 1 for i in range(len(matrix)) for j in range(len(matrix)) if i != j)

 

A>

from operator import itemgetter

def capture(matrix):
    column, saw = [[0, 0]], [0]
    while len(column):
        min_point = min(column, key=itemgetter(1))
        column.pop(column.index(min_point))
        point, old_value = min_point
        for i, value in enumerate(matrix[point]):
            if value and not i == point and not i in saw:
                matrix[i][i] = matrix[i][i] + matrix[point][point]
                column.append([i, matrix[i][i]])
                saw.append(i)

    return max(map(max, matrix))

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert capture([[0, 1, 0, 1, 0, 1],
                    [1, 8, 1, 0, 0, 0],
                    [0, 1, 2, 0, 0, 1],
                    [1, 0, 0, 1, 1, 0],
                    [0, 0, 0, 1, 3, 1],
                    [1, 0, 1, 0, 1, 2]]) == 8, "Base example"
    assert capture([[0, 1, 0, 1, 0, 1],
                    [1, 1, 1, 0, 0, 0],
                    [0, 1, 2, 0, 0, 1],
                    [1, 0, 0, 1, 1, 0],
                    [0, 0, 0, 1, 3, 1],
                    [1, 0, 1, 0, 1, 2]]) == 4, "Low security"
    assert capture([[0, 1, 1],
                    [1, 9, 1],
                    [1, 1, 9]]) == 9, "Small"

 

O>

Pass:capture([[0,1,1,0,0,1],[1,6,1,0,1,1],[1,1,3,0,1,0],[0,0,0,9,1,0],[0,1,1,1,4,0],[1,1,0,0,0,6]])

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 96  (0) 2019.06.24
Python Learn the basics Quiz 95  (0) 2019.06.24
Python Learn the basics Quiz 93  (0) 2019.06.23
Python Learn the basics Quiz 92  (0) 2019.06.22
Python Learn the basics Quiz 91  (0) 2019.06.21