📜  最大相交点n个圆

📅  最后修改于: 2021-04-29 16:59:58             🧑  作者: Mango

给定数字n,我们需要找到n个圆相交的最大次数。
例子:

Input :  n = 2
Output : 2

Input :  n = 3
Output : 6

描述和派生

如上图所示,对于每对圆,最多可以有两个交叉点。因此,如果我们有n个圆,则可以有n个C 2对圆,其中每对将有两个交点。因此,我们可以得出这样的结论:通过查看所有可能的圆对,可以得出2 * n C 2给出n个圆的最大相交数的数学公式。
2 * n C 2 = 2 * n *(n – 1)/ 2 = n *(n-1)

C++
// CPP program to find maximum umber of
// intersections of n circles
#include 
using namespace std;
 
// Returns maximum number of intersections
int intersection(int n)
{
   return n * (n - 1);
}
 
int main()
{
    cout << intersection(3) << endl;
    return 0;
}
// This code is contributed by
// Manish Kumar Rai.


Java
// Java program to find maximum umber of
// intersections of n circles
import java.io.*;
 
public class GFG {
 
    // for the calculation of 2*(nC2)
    static int intersection(int n)
    {
       return n * (n - 1);
    }
 
    public static void main(String[] args) throws IOException
    {
        System.out.println(intersection(3));
    }
}
// This code is contributed by
// Manish Kumar Rai


Python3
# python program to find maximum umber of
# intersections of n circles
# Returns maximum number of intersections
def intersection(n):
     
   return n * (n - 1);
 
# Driver code
print(intersection(3))
 
# This code is contributed by Sam007


C#
// C# program to find maximum umber of
// intersections of n circles
using System;
class GFG {
 
    // for the calculation of 2*(nC2)
    static int intersection(int n)
    {
        return n * (n - 1);
    }
 
// Driver Code
public static void Main()
{
    Console.WriteLine(intersection(3));
}
 
}
 
// This code is contributed by Sam007


php


Javascript


输出:
6