📌  相关文章
📜  N个男孩坐在圆桌旁的座位安排,以使两个特定的男孩坐在一起

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

N个男孩坐在圆桌旁。任务是找到N个男孩可以坐在圆桌旁以使两个特定男孩坐在一起的方式。
例子:

方法:

  • 首先,两个可以安排两个男孩!方法。
  • 剩余的男孩和前两个男孩对的排列方式为(n – 1)!。
  • 因此,总计方式= 2! *(n – 1)!

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to return the total count of ways
int Total_Ways(int n)
{
 
    // Find (n - 1) factorial
    int fac = 1;
    for (int i = 2; i <= n - 1; i++) {
        fac = fac * i;
    }
 
    // Return (n - 1)! * 2!
    return (fac * 2);
}
 
// Driver code
int main()
{
    int n = 5;
 
    cout << Total_Ways(n);
 
    return 0;
}


Java
// Java implementation of the approach
import java.io.*;
 
class GFG
{
     
// Function to return the total count of ways
static int Total_Ways(int n)
{
 
    // Find (n - 1) factorial
    int fac = 1;
    for (int i = 2; i <= n - 1; i++)
    {
        fac = fac * i;
    }
 
    // Return (n - 1)! * 2!
    return (fac * 2);
}
 
// Driver code
public static void main (String[] args)
{
 
    int n = 5;
 
    System.out.println (Total_Ways(n));
}
}
 
// This code is contributed by Tushil.


Python3
# Python3 implementation of the approach
 
# Function to return the total count of ways
def Total_Ways(n) :
 
    # Find (n - 1) factorial
    fac = 1;
    for i in range(2, n) :
        fac = fac * i;
         
    # Return (n - 1)! * 2!
    return (fac * 2);
 
 
# Driver code
if __name__ == "__main__" :
 
    n = 5;
 
    print(Total_Ways(n));
 
# This code is contributed by AnkitRai01


C#
// C# implementation of the approach
using System;
 
class GFG
{
 
// Function to return the total count of ways
static int Total_Ways(int n)
{
 
    // Find (n - 1) factorial
    int fac = 1;
    for (int i = 2; i <= n - 1; i++)
    {
        fac = fac * i;
    }
 
    // Return (n - 1)! * 2!
    return (fac * 2);
}
 
// Driver code
static public void Main ()
{
    int n = 5;
 
    Console.Write(Total_Ways(n));
}
}
 
// This code is contributed by ajit..


Javascript


输出:
48