Hej,
przejdę od razu do rzeczy. Robię jedno z zadań w Python na pewnej stronie.
Treść:
Given a room's size and a list of PIR sensors mounted on the room's ceiling and looking down on the floor, your task is to determine whether the floor area is completely into the sensors coverage area (return True) or not (return False). The bottom left corner of the rectangle matches the origin point O, the top right corner is defined by W and H. Each sensor is defined by its mounting point (coordinates xi and yi) and its range (Ri).
Input: Two arguments:
the first is a list containing a room's top right corner coordinates,all are integers [W, H]
the second is a list containing sensors info, all are integers xi, yi, Ri], [xi+1, yi+1, Ri+1], ....., [xn, yn, Rn
Output: True or False.
Kod:
import math
def is_covered(room, sensors):
len_of_sensor = len(sensors) #ilość sensorów
mid_of_x = room[0]/2 #środek pokoju
mid_of_y = room[1]/2 #środek pokoju
x_of_sensor = [item[0] for item in sensors]
y_of_sensor = [item[1] for item in sensors]
r_of_sensor = [item[-1] for item in sensors]
r_of_room = int((math.sqrt(room[0] ** 2 + room[1] ** 2))/2) #polowa przekatnej pokoju
range_of_every_sensor = [] #range każdego okręgu w liście
pole_okregow_razem = 0 #pole wszystkich sensorow razem
pole_pokoju = room[0] * room[1] #pole pokoju
if len_of_sensor == 1:
if mid_of_x == sensors[0][0] and mid_of_y == sensors[0][1]:
if r_of_sensor[0] >= r_of_room:
return True
else:
return False
else:
for lista in sensors:
range_of_every_sensor.append(lista[-1])
for x in range_of_every_sensor:
pole_all_okregow_razem += 3.14 * x**2
if pole_okregow_razem < pole_pokoju:
return False
else:
if __name__ == '__main__':
print(is_covered([200, 150], [[100, 75, 130]])) == True
print(is_covered([200, 150], [[50, 75, 100], [150, 75, 100]])) == True
print(is_covered([200, 150], [[50, 75, 100], [150, 25, 50], [150, 125, 50]])) == False
print(is_covered([200, 150], [[100, 75, 100], [0, 40, 60], [0, 110, 60], [200, 40, 60], [200, 110, 60]])) == True
print(is_covered([200, 150], [[100, 75, 100], [0, 40, 50], [0, 110, 50], [200, 40, 50], [200, 110, 50]])) == False
print(is_covered([200, 150], [[100, 75, 110], [105, 75, 110]])) == False
print(is_covered([200, 150], [[100, 75, 110], [105, 75, 20]])) == False
print(is_covered([3, 1], [[1, 0, 2], [2, 1, 2]])) == True
print(is_covered([30, 10], [[0, 10, 10], [10, 0, 10], [20, 10, 10], [30, 0, 10]])) == True
print(is_covered([30, 10], [[0, 10, 8], [10, 0, 7], [20, 10, 9], [30, 0, 10]])) == False
Czyli po prostu trzeba wykazać czy wszystkie sensory pokryją razem całą powierzchnie pokoju.
Na razie jedyne co mi się udało wymyślić to kawałek kodu to pokoju, który ma jeden sensor i jest on na środku tego pomieszczenia.
Nie chodzi mi też o to by ktoś mi tu podawał całą resztę kodu tylko jakąś podpowiedź.
Najlepiej jakby ktoś mógłby mi wytłumaczyć tylko i wyłącznie działanie jakie mam wykonać, a ja już sam się zajmę przerobieniem tego na kod.
Z chęcią przyjmę każda podpowiedź Uśmiech
Z góry bardzo dziękuje i pozdrawiam! Chichot