arr = Array.from(new Array(4)).map(x => readline()).join(' ').split(' ').map(x => parseInt(x)) m = arr[0],n = arr[1] while (arr.length < n * 2 + m + 2){ arr.push(arr[arr.length - 1]) } h = Array.from(new Array(n)).map((x,y) => [arr[y + 2],arr[y + n + 2]]).sort((x,y) => x[1] > y[1] ? 1 : -1) p = Array.from(new Array(m)).map((x,y) => arr[y + n * 2 + 2]) n = 0 while (n < h.length){ n ++ while (n < h.length && h[n][0] <= h[n - 1][0]){ h.splice(n,1) } } for (var i = 0; i < m ; i ++){ t = h.filter(x => x[1] <= p[i]) print(t.length == 0 ? -1 : t[t.length -1][1]) } 将上面代码用python实现,最终完整的结果
时间: 2024-04-15 18:27:32 浏览: 118
以下是将给定的 JavaScript 代码转换为 Python 代码的最终结果:
```python
arr = []
for _ in range(4):
arr.append(list(map(int, input().split())))
m = arr[0][0]
n = arr[1][0]
while len(arr) < n * 2 + m + 2:
arr.append(arr[-1])
h = [[arr[y + 2][0], arr[y + n + 2][0]] for y in range(n)]
h.sort(key=lambda x: x[1])
p = [arr[y + n * 2 + 2][0] for y in range(m)]
n = 0
while n < len(h):
n += 1
while n < len(h) and h[n][0] <= h[n - 1][0]:
h.pop(n)
for i in range(m):
t = [x for x in h if x[1] <= p[i]]
print(-1 if len(t) == 0 else t[-1][1])
```
请注意,此处假设您输入的是 4 行整数数据。如果实际情况不同,请相应地调整输入部分的代码。
相关问题
arr = Array.from(new Array(4)).map(x => readline()).join(' ').split(' ').map(x => parseInt(x)) m = arr[0],n = arr[1] while (arr.length < n * 2 + m + 2){ arr.push(arr[arr.length - 1]) } h = Array.from(new Array(n)).map((x,y) => [arr[y + 2],arr[y + n + 2]]).sort((x,y) => x[1] > y[1] ? 1 : -1) p = Array.from(new Array(m)).map((x,y) => arr[y + n * 2 + 2]) n = 0 while (n < h.length){ n ++ while (n < h.length && h[n][0] <= h[n - 1][0]){ h.splice(n,1) } } for (var i = 0; i < m ; i ++){ t = h.filter(x => x[1] <= p[i]) print(t.length == 0 ? -1 : t[t.length -1][1]) } 将上面代码用python实现
你可以使用以下代码将上述 JavaScript 代码转换为 Python 代码:
```python
arr = [int(x) for x in input().split()]
m, n = arr[0], arr[1]
while len(arr) < n * 2 + m + 2:
arr.append(arr[-1])
h = [[arr[y + 2], arr[y + n + 2]] for y in range(n)]
h.sort(key=lambda x: x[1])
p = [arr[y + n * 2 + 2] for y in range(m)]
n = 0
while n < len(h):
n += 1
while n < len(h) and h[n][0] <= h[n - 1][0]:
h.pop(n)
for i in range(m):
t = [x for x in h if x[1] <= p[i]]
print(-1 if len(t) == 0 else t[-1][1])
```
请注意,这只是简单地将 JavaScript 代码转换为 Python 代码,可能需要根据实际情况进行进一步调整。
阅读全文