📌  相关文章
📜  检查两个凸正多边形是否具有相同的中心

📅  最后修改于: 2021-04-23 06:09:19             🧑  作者: Mango

给定两个正整数N和M,它们表示凸正多边形的边,其中N 多边形中心:指向与多边形的每个顶点等距的多边形内部。
例子:

方法:此问题的主要观察结果是,当M%N == 0时,这意味着N边多边形的边均等地覆盖了M边多边形的边,这意味着这两个多边形的中心相同。
算法:

  • 检查M是否可被N整除,如果是,则两个多边形的中心相同。
  • 否则,两个多边形的中心都不同。

下面是上述方法的实现:

C++
// C++ implementation to check whether
// two convex polygons have same center
 
#include
using namespace std;
 
// Function to check whether two convex
// polygons have the same center or not
int check(int n, int m){
    if (m % n == 0){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
}
 
// Driver Code
int main()
{
    int n = 5;
    int m = 10;
     
    check(n, m);
    return 0;
}


Java
// Java implementation to check whether
// two convex polygons have same center
class GFG{
  
// Function to check whether two convex
// polygons have the same center or not
static int check(int n, int m){
    if (m % n == 0){
        System.out.print("YES");
    }
    else{
        System.out.print("NO");
    }
    return 0;
}
  
// Driver Code
public static void main(String[] args)
{
    int n = 5;
    int m = 10;
      
    check(n, m);
}
}
 
// This code is contributed by sapnasingh4991


Python3
# Python3 implementation to check whether
# two convex polygons have same center
 
# Function to check whether two convex
# polygons have the same center or not
def check(n, m):
    if (m % n == 0):
        print("YES")
    else:
        print("NO")
 
# Driver Code
n = 5
m = 10
 
check(n, m)
 
# This code is contributed by mohit kumar 29


C#
// C# implementation to check whether
// two convex polygons have same center
using System;
 
class GFG{
   
// Function to check whether two convex
// polygons have the same center or not
static int check(int n, int m){
    if (m % n == 0){
        Console.Write("YES");
    }
    else{
        Console.Write("NO");
    }
    return 0;
}
   
// Driver Code
public static void Main(String[] args)
{
    int n = 5;
    int m = 10;
       
    check(n, m);
}
}
  
// This code is contributed by Rajput-Ji


Javascript


输出:
YES

性能分析:

  • 时间复杂度: O(1)。
  • 辅助空间: O(1)。