📜  计划找到参加课程的最低人数要求保持75%

📅  最后修改于: 2021-04-23 15:57:08             🧑  作者: Mango

考虑主题数据结构,截止到目前,该数据结构的课程总数为M ,而有些学生仅参加N这些类之外。找到他们必须参加的最少讲座数目,以便他们75\%出席率保持不变。

例子:

解决方案:
使用公式,
 Ceil\left (\frac{(0.75*M)-N}{0.25}  \right )

在应用公式之前,首先检查N by M是否具有75%,如果不是,则应用公式

C++
// C++ Program to find minimum number of lectures to attend
// to maintain 75% attendance
  
#include 
#include 
using namespace std;
  
// Function to compute minimum lecture
int minimumLectures(int m, int n)
{
    int ans = 0;
  
    // Formula to compute
    if (n < (int)ceil(0.75 * m))
        ans = (int)ceil(((0.75 * m) - n) / 0.25);
    else
        ans = 0;
  
    return ans;
}
  
// Driver function
int main()
{
    int M = 9, N = 1;
    cout << minimumLectures(M, N);
    return 0;
}


Java
// Java Program to find minimum number of lectures to attend
// to maintain 75% attendance
  
public class GFG {
  
    // Method to compute minimum lecture
    static int minimumLectures(int m, int n)
    {
        int ans = 0;
  
        // Formula to compute
        if (n < (int)Math.ceil(0.75 * m))
            ans = (int)Math.ceil(((0.75 * m) - n) / 0.25);
        else
            ans = 0;
  
        return ans;
    }
  
    // Driver Code
    public static void main(String[] args)
    {
        int M = 9, N = 1;
        System.out.println(minimumLectures(M, N));
    }
}


Python
# Python Program to find minimum number of lectures to attend
# to maintain 75 % attendance
  
import math
  
# Function to compute minimum lecture
def minimumLecture(m, n):
    ans = 0
  
    # Formula to compute
    if(n < math.ceil(0.75 * m)):
        ans = math.ceil(((0.75 * m) - n) / 0.25)
    else:
        ans = 0
    return ans
  
# Driver Code
  
M = 9
N = 1
  
print(minimumLecture(M, N))


C#
// C# Program to find minimum
// number of lectures to attend 
// to maintain 75% attendance 
using System;
  
class GFG 
{ 
  
// Method to compute minimum lecture 
static int minimumLectures(int m, int n) 
{ 
    int ans = 0; 
  
    // Formula to compute 
    if (n < (int)Math.Ceiling(0.75 * m)) 
        ans = (int)Math.Ceiling(((0.75 * m) - 
                                 n) / 0.25); 
    else
        ans = 0; 
  
    return ans; 
} 
  
// Driver Code 
public static void Main() 
{ 
    int M = 9, N = 1; 
    Console.WriteLine(minimumLectures(M, N)); 
} 
} 
  
// This code is contributed 
// by anuj_67


PHP


输出:

23