Finding pairs with product greater than sum

前端 未结 5 1998
长发绾君心
长发绾君心 2020-12-13 22:04

Given as input, a sorted array of floats, I need to find the total number of pairs (i,j) such as A[i]*A[j]>=A[i]+A[j] for each i < j

5条回答
  •  抹茶落季
    2020-12-13 22:35

    How about excluding all floats that less then 1.0 first, since any number multiple with number less than 1, the x*0.3=A[i]+A[j] for each i < j, so we only need to count numbers of array to calculate the number of pairs(i, j), we can use formula about permutation and combination to calculate it. formula should be n(n-1)/2.

提交回复
热议问题