Arrangements for meetings and conference rooms

Meeting and meeting room arrangements

problem

Meeting scheduling issues. There is a group of meeting A and a group of meeting room B. A[i] represents the number of participants in the i-th meeting, and B[j] represents the maximum number of people that can be accommodated in the j-th meeting room.
If and only if A[i]<=B[j], the j-th meeting room can be used to hold the i-th meeting. Given array A and array B, how many meetings can be held simultaneously.

    Example

    A={
        
        123};
    B={
        
        324};
    Return 3
    
    A={
        
        3,4,3,1};
    B={
        
        1,2,2,6};
    Return 2;
    

    • Algorithm

      The meeting room arrangement problem is similar to the meeting scheduling problem, which can be associated with trying a greedy algorithm.

      Each time, arrange as many participants as possible in the unscheduled conference room with the largest capacity, that is, for each conference room, arrange the conference with the largest number of participants among the currently unscheduled conferences. If it can be accommodated, select the meeting, otherwise find a meeting with more participants to arrange until you find a meeting that can accommodate.

      At the beginning of the exam, my mind was very unconscious. When I did this question, I thought of dynamic programming at first, and then I was thinking about how to formulate the state transition equation. It took a while to think of the problem of arranging meetings according to spare time, so I tried to use greedy algorithms. I sorted out my thoughts and wrote it down according to the greedy algorithm before it passed.

      code show as below.

    class Solution {
        
        
    public: 
        int arrange(vector<int> A,vector<int> B){
        
        
            int a=A.size(),b=B.size();
            sort(A.begin(),A.end());
            sort(B.begin(),B.end());
            int sum=0;
            int i=a-1,j=b-1;
    
            for(i;i>=0;i--){
        
        
                if(A[i]<=B[j]&&j>=0){
        
        
                    sum++;
                    j--;
                }
            }
            return sum; 
        }
    };
    

    Guess you like

    Origin blog.csdn.net/hhb442/article/details/109173459