给定一个整数数组A,N我们N在2D平面中绘制光盘,使得第i个光盘具有中心(0,i)和半径A[i].如果第k个和第j个盘具有至少一个公共点,我们说第k个盘和第j个盘相交.
写一个函数
int number_of_disc_intersections(int[] A);
Run Code Online (Sandbox Code Playgroud)
给出如上所述的A描述N盘的阵列,返回交叉盘对的数量.例如,给定N=6和
A[0] = 1
A[1] = 5
A[2] = 2
A[3] = 1
A[4] = 4
A[5] = 0
Run Code Online (Sandbox Code Playgroud)
共有11对交叉盘:
0th and 1st
0th and 2nd
0th and 4th
1st and 2nd
1st and 3rd
1st and 4th
1st and 5th
2nd and 3rd
2nd and 4th
3rd and 4th
4th and 5th
Run Code Online (Sandbox Code Playgroud)
所以函数应该返回11.如果相交对的数量超过10,000,000,函数应该返回-1.该函数可以假设N不超过10,000,000.