小编Adi*_*oop的帖子

计算两个排列中的对 (a,b) 使得 index(a) < index(b) 在两个排列中

给定 (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)

algorithm data-structures

17
推荐指数
2
解决办法
741
查看次数

在C++中调用成员函数而不创建对象

谁能解释为什么我们可以在不创建对象实例的情况下调用静态成员函数,但在非静态函数的情况下却不能?

我到处搜索,我找不到解释,你能帮忙吗?

c++ c++14

5
推荐指数
1
解决办法
4213
查看次数

标签 统计

algorithm ×1

c++ ×1

c++14 ×1

data-structures ×1