Television Set
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#include <stdio.h>
#define mod 1000000007
#define MAX_LENGTH 1000
typedef long long int lld;
int isPalindrome(char str[], int start, int end) {
while (start < end) {
if (str[start] != str[end]) {
return 0; // Not a palindrome
}
start++;
end--;
}
return 1; // Palindrome
}
int main() {
char s[MAX_LENGTH], s1[MAX_LENGTH], s2[MAX_LENGTH], s3[MAX_LENGTH];
scanf("%s", s);
int l = 0;
while (s[l] != '\0') {
l++;
}
for (int i = 1; i < l - 1; i++) {
for (int k = 0; k < i; k++) {
s1[k] = s[k];
}
s1[i] = '\0';
if (isPalindrome(s, 0, i - 1)) {
for (int j = 1; j < l - i; j++) {
for (int k = 0; k < j; k++) {
s2[k] = s[i + k];
}
s2[j] = '\0';
for (int k = 0; k < l - i - j; k++) {
s3[k] = s[i + j + k];
}
s3[l - i - j] = '\0';
if (isPalindrome(s2, 0, j - 1) && isPalindrome(s3, 0, l - i - j - 1)) {
printf("%s\n%s\n%s\n", s1, s2, s3);
return 0;
}
}
}
}
printf("Impossible\n");
return 0;
}
No comments:
Post a Comment