- Related Questions & Answers
- Find if neat arrangement of cups and shelves can be made in Python
- Is pizza healthy? If not, can it be made healthy?
- How can Indian prisons be made secure?
- Can a constructor be made final in Java?
- Find if n can be written as product of k numbers in C++
- Count of numbers which can be made power of 2 by given operation in C++
- Maximum elements that can be made equal with k updates in C++
- Find if array can be divided into two subarrays of equal sum in C++
- Program to find the length of the longest, that can be made using given letters in Python
- Beautiful Arrangement in C++
- Print all possible strings that can be made by placing spaces in C++
- Maximum number of parallelograms that can be made using the given length of line segments in C++
- Beautiful Arrangement II in C++
- Maximum height of triangular arrangement of array values in C++
- How changes, made in the current transaction, can be permanently recorded in MySQL database?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

With respect of given three different types of cups (p[]) and saucers (q[]), and m numberof shelves, determine if neat arrangement of cups and shelves can be made.

Now, arrangement of the cups and saucers will be neat if it follows the following rules −

- According to first rule, no shelf can contain both cups and saucers.
- According to second rule, there can be no more than 5 cups in any shelf.
- According to third rule, there can be no more than 10 saucers in any shelf.

p[] = {4, 3, 7} q[] = {5, 9, 10} m = 11

Yes

Total cups = 14, shelves required = 3

Total saucers = 24, shelves required = 3

So, total required shelves = 3 + 3 = 6,

which is smaller than given number of shelves m. So, output is Yes.

p[] = {5, 8, 5} q[] = {4, 10, 11} m = 3

No

Total cups = 18, shelves required = 4

Total saucers = 25, shelves required = 3

So, total required shelves = 4 + 3 = 7,

which is larger than given number of shelves m. So, output is No.

For arranging the cups and the saucers, determine the total number of cups p and total number of saucers q. Because, it is not possible to be more than 5 cups in the sameshelf, therefore determine the maximum number of shelves required for cup by the formula (p+5-1)/5 and the maximum number of shelves required for saucers by implementing the formula (q+10-1)/10. It has been seen that if sum of these two values is equal to or smaller than m then the arrangement is possible else not.

// C++ code to find if neat // arrangement of cups and // shelves can be made #include<bits/stdc++.h> using namespace std; // Shows function to check arrangement void canArrange1(int p[], int q[], int m){ int sump = 0, sumq = 0; // Used to calculate total number // of cups for(int i = 0; i < 3; i++) sump += p[i]; // Used to calculate total number // of saucers for(int i = 0; i < 3; i++) sumq += q[i]; // Now adding 5 and 10 so that if the // total sum is smaller than 5 and // 10 then we can get 1 as the // answer and not 0 int mp = (sump + 5 - 1) / 5; int mq = (sumq + 10 - 1) / 10; if(mp + mq <= m) cout << "Yes"; else cout << "No"; } // Driver code int main(){ // Shows number of cups of each type int p[] = {4, 3, 7}; // Shows number of saucers of each type int q[] = {5, 9, 10}; // Shows number of shelves int m = 10; // ndicates calling function canArrange1(p, q, m); return 0; }

Yes

Advertisements