質問編集履歴

1

SplPriorityQueueを使ってやりたいことを追記

2022/02/10 09:44

投稿

MonsterEnergy
MonsterEnergy

スコア14

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,70 @@
15
15
  ②なぜ上記のソース箇所にはメソッドの中身がないのでしょうか?**
16
16
 
17
17
  よろしくお願い致します。
18
+
19
+ 追記------------------------------------------------------------------------------------
20
+ SplPriorityQueueを使ってやりたいことは以下のようなものです。優先度付きキューを使わない方法もあると思いますが、優先度付きキューを使って解決したいです。
21
+ [[1,1,0,0,0],
22
+ [1,1,1,1,0],
23
+ [1,0,0,0,0],
24
+ [1,1,0,0,0],
25
+ [1,1,1,1,1]],
26
+ という各要素が配列の配列を与えられたら、
27
+ この各要素内の1の数を比較して、1が大きい順に順位をつけます。
28
+ 1の数が同じ場合は、配列内のインデックス番号が大きい方が順位を上にしたいです。
29
+ その順位付けをSplPriorityQueueを使って実行したいです。
30
+
31
+ > You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.
32
+ >
33
+ > A row i is weaker than a row j if one of the following is true:
34
+ >
35
+ > The number of soldiers in row i is less than the number of soldiers in row j.
36
+ > Both rows have the same number of soldiers and i < j.
37
+ > Return the indices of the k weakest rows in the matrix ordered from weakest to strongest.
38
+ >
39
+ >
40
+ >
41
+ > Example 1:
42
+ >
43
+ > Input: mat =
44
+ > [[1,1,0,0,0],
45
+ > [1,1,1,1,0],
46
+ > [1,0,0,0,0],
47
+ > [1,1,0,0,0],
48
+ > [1,1,1,1,1]],
49
+ > k = 3
50
+ > Output: [2,0,3]
51
+ > Explanation:
52
+ > The number of soldiers in each row is:
53
+ > - Row 0: 2
54
+ > - Row 1: 4
55
+ > - Row 2: 1
56
+ > - Row 3: 2
57
+ > - Row 4: 5
58
+ > The rows ordered from weakest to strongest are [2,0,3,1,4].
59
+ > Example 2:
60
+ >
61
+ > Input: mat =
62
+ > [[1,0,0,0],
63
+ > [1,1,1,1],
64
+ > [1,0,0,0],
65
+ > [1,0,0,0]],
66
+ > k = 2
67
+ > Output: [0,2]
68
+ > Explanation:
69
+ > The number of soldiers in each row is:
70
+ > - Row 0: 1
71
+ > - Row 1: 4
72
+ > - Row 2: 1
73
+ > - Row 3: 1
74
+ > The rows ordered from weakest to strongest are [0,2,3,1].
75
+ >
76
+ >
77
+ > Constraints:
78
+ >
79
+ > m == mat.length
80
+ > n == mat[i].length
81
+ > 2 <= n, m <= 100
82
+ > 1 <= k <= m
83
+ > matrix[i][j] is either 0 or 1.
84
+