Television Sets
Problem Description
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
Input Format
First line provides an integer N that denotes the number of rooms in the hospital
Second line provides two space-delimited integers that denote the rates of rooms with TV (R1) and without TV (R2) respectively
Third line provides the revenue target
Output
Minimum number of TVs the hospital needs to buy to meet its revenue target. If it cannot achieve its target, print the total number of rooms in the hospital.
Timeout
1
Test Case
Example 1
Input
20
1500 1000
7000000
Output
14
Explanation
Using the formula, number of patients on 1st Jan will be 39, on 2nd Jan will be 38 and so on. Considering there are only twenty rooms and rates of both type of rooms are 1500 and 1000 respectively, we will need 14 TV sets to get revenue of 7119500. With 13 TV sets Total revenue will be less than 7000000
Example 2
Input
10
1000 1500
10000000
Output
10
Explanation
In the above example, the target will not be achieved, even by equipping all the rooms with TV. Hence, the answer is 10 i.e. total number of rooms in the hospital.
Answers
Answer:
//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.
Language used: Python programming
Program:
no_of_rooms=int(input())
with_ac, without_ac=map(int,input().split(' '))
estimation=int(input())
month_days=[31,28,31,30,31,30,31,31,30,31,30,31]
money,total=0,0
per_month,total_year=[],[]
for i in range(len(month_days)):
for j in range(1,month_days[i]+1):
per_month.append((6-(i+1))*(6-(i+1))+abs(j-15))
total_year.append(per_month)
per_month=[]
for i in range(no_of_rooms+1):
for j in total_year:
for k in j:
if(k>=no_of_rooms):
t=no_of_rooms-i
money=money+(i*with_ac+t*without_ac)
else:
h=no_of_rooms-i
t=k-h
if(t<=0):
money=money+(k*without_ac)
else:
money=money+(t*with_ac+h*without_ac)
total=total+money
money=0
if(total>=estimation):
print(i)
break
else:
total=0
else:
print(no_of_rooms)
Sample Input:
20
1500 1000
7000000
Output:
14
As given in the question, "the number of patients on 1st Jan will be 39, on 2nd Jan will be 38 and so on. Considering there are only twenty rooms and rates of both type of rooms are 1500 and 1000 respectively, we will need 14 TV sets to get revenue of 7119500. With 13 TV sets, Total revenue will be less than 7000000."
Learn more:
1) Printing all the palindromes formed by a palindrome word.
brainly.in/question/19151384
2) Indentation is must in python. Know more about it at :
brainly.in/question/17731168