Computer Science, asked by siddeswariReddy, 10 months ago

Dr. Vishnu is opening a new world class hospital in a small town designed to be the first preference of the patients in the city. Hospital has N rooms of two types - with TV and without TV, with daily rates of R1 and R2 respectively. However, from his experience Dr. Vishnu knows that the number of patients is not constant throughout the year, instead it follows a pattern. The number of patients on any given day of the year is given by the following formula – (6-M)^2 + |D-15| where M is the number of month (1 for jan, 2 for feb ...12 for dec) and D is the date (1,2...31). All patients prefer without TV rooms as they are cheaper, but will opt for with TV rooms only if without TV rooms are not available. Hospital has a revenue target for the first year of operation. Given this target and the values of N, R1 and R2 you need to identify the number of TVs the hospital should buy so that it meets the revenue target. Assume the Hospital opens on 1st Jan and year is a non-leap year. Constraints Hospital opens on 1st Jan in an ordinary year 5 <= Number of rooms <= 100 500 <= Room Rates <= 5000 0 <= Target revenue < 90000000

Answers

Answered by joysarkar0898
0

//This is The Coding Area

#include<bits/stdc++.h>

using namespace std;

int main()

{

int n;

cin>>n;

 

int r1,r2,rt;

 

cin>>r1>>r2>>rt;

 

int a[n+1];

memset(a,0,sizeof(a));

 

int s;

int a1[12]={31,28,31,30,31,30,31,31,30,31,30,31};

for(int i=1;i<=12;i++)  //month loop

{

    for(int j=1;j<=a1[i-1];j++)  // day loop

    {

     int k=6-i;

     int d=min(n,((k*k)+abs(j-15)));

       

     for(int k=0;k<=n;k++)  // loop  of rooms

     {

         int p1,p2;

         p1=k;p2=n-k;

           

         int left;

           

         if(p2>=d)

         a[k]+=d*r2;

         else

         {

             left=d-p2;

             a[k]+=(left*r1+p2*r2);

         }

     }

    }

}

 

int no_of_rooms=0;

for(int i=0;i<=n;i++)

{

    no_of_rooms=i;

    if(a[i]>=rt)

    break;

}

cout<<no_of_rooms;

 

}

Explanation:

We iterate through each day of each month so that the no. of visitors can be found. once we find the no visitors, we notice that only N of them can be accomodated. eg : if there are 31 patients but 20 rooms , we only 20 people can get rooms. Now we check all combinations of rooms and keep the summation of the revenue generated by them in the room array (array : a in the above code). then we iterate through 1 to n to find the no. of rooms needed.

Similar questions