📜  程序在平面图中查找区域数

📅  最后修改于: 2021-05-04 19:07:05             🧑  作者: Mango

给定两个整数VE ,它们表示平面图的顶点和边的数量。任务是找到该平面图的区域数。

平面图平面图是指没有边彼此相交的图,或者可以在没有边相交的情况下在平面上绘制的图称为平面图。

区域:绘制没有边缘相交的平面图时,图的边缘和顶点会将平面划分为多个区域。

例子:

方法:欧拉发现平面图中的区域数量是顶点数量和图中边数的函数,即

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the number
// of regions in a Planar Graph
int Regions(int Vertices, int Edges)
{
    int R = Edges + 2 - Vertices;
 
    return R;
}
 
// Driver code
int main()
{
    int V = 5, E = 7;
 
    cout << Regions(V, E);
 
    return 0;
}


Java
// Java implementation of the approach
import java.io.*;
 
class GFG {
 
    // Function to return the number
    // of regions in a Planar Graph
    static int Regions(int Vertices, int Edges)
    {
        int R = Edges + 2 - Vertices;
 
        return R;
    }
 
    // Driver code
    public static void main(String[] args)
    {
 
        int V = 5, E = 7;
        System.out.println(Regions(V, E));
    }
}
 
// This code is contributed by akt_mit


Python3
# Python3 implementation of the approach
 
# Function to return the number
# of regions in a Planar Graph
def Regions(Vertices, Edges) :
 
    R = Edges + 2 - Vertices;
 
    return R;
 
# Driver code
if __name__ == "__main__" :
 
    V = 5; E = 7;
 
    print(Regions(V, E));
 
# This code is contributed
# by AnkitRai01


C#
// C# implementation of the approach
using System;
 
class GFG {
 
    // Function to return the number
    // of regions in a Planar Graph
    static int Regions(int Vertices, int Edges)
    {
        int R = Edges + 2 - Vertices;
 
        return R;
    }
 
    // Driver code
    static public void Main()
    {
 
        int V = 5, E = 7;
        Console.WriteLine(Regions(V, E));
    }
}
 
// This code is contributed by ajit


PHP


Javascript


输出:
4