给定 (1, 2, 3,..N) 的两个排列,
Consider for n = 5
5 4 3 2 1
3 2 4 1 5
Run Code Online (Sandbox Code Playgroud)
在两个排列中找到使 index(a)<index(b) 的对 (a,b) 的数量?
在上述情况下,答案是 4。
(4,1) index(4)<index(1) in both permutations.
(3,1)
(2,1)
(3,2)
Run Code Online (Sandbox Code Playgroud)
我们可以在 O(n 2 ) 中轻松完成此操作,但我觉得我们可以在 O(nlogn) 中完成此操作。你能帮忙吗?
另一个例子...
for n = 5
3 4 1 5 2
1 3 2 5 4
Run Code Online (Sandbox Code Playgroud)
这里的答案是 5
(3,4) index(3)<index(4) in both perms.
(3,5) index(3)<index(5) in both perms.
(3,2)
(1,5)
(1,2)
Run Code Online (Sandbox Code Playgroud) 谁能解释为什么我们可以在不创建对象实例的情况下调用静态成员函数,但在非静态函数的情况下却不能?
我到处搜索,我找不到解释,你能帮忙吗?