给定一个由N
个整数组成的数组A
,我们在二维平面上绘制N
个圆盘,其中第i个圆盘的中心为(0,i)
,半径为A[i]
。 如果第k个圆盘和第j个圆盘有至少一个公共点,则称第k个圆盘和第j个圆盘相交。
编写一个函数
int number_of_disc_intersections(int[] A);
给定一个描述N
个圆盘的数组A
,如上所述,返回相交圆盘对的数量。例如,给定N=6
和
A[0] = 1
A[1] = 5
A[2] = 2
A[3] = 1
A[4] = 4
A[5] = 0
有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
因此该函数应返回11。
如果相交对数超过10,000,000, 该函数应返回-1。该函数可以假设N
不超过10,000,000。