- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to check we can place dominos on colored cells in correct order or not
Suppose we have five numbers n, k1, k2, w and b. There is a board with 2 x n cells and first k1 cells in the first row, first k2 cells in second row are colored in white. All other cells are black. We have w white dominos and b black dominos (2 x 1 size). We can place a white domino on the board if both board's cells are white and not occupied by any other domino. In the same way, a black domino can be placed if both cells are black and not occupied by any other domino. We have to check whether we can place all w + b dominoes on the board if they are placed both horizontally and vertically?
So, if the input is like n = 5; k1 = 4; k2 = 3; w = 3; b = 1, then the output will be True.
Steps
To solve this, we will follow these steps −
if 2 * w <= (k1 + k2) and 2 * b <= (n - k1 + n - k2), then: return true Otherwise return false
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; bool solve(int n, int k1, int k2, int w, int b) { if (2 * w <= (k1 + k2) && 2 * b <= (n - k1 + n - k2)) { return true; } else { return false; } } int main() { int n = 5; int k1 = 4; int k2 = 3; int w = 3; int b = 1; cout << solve(n, k1, k2, w, b) << endl; }
Input
5, 4, 3, 3, 1
Output
1
- Related Articles
- C++ Program to check cats words are right or not with colored hats
- C++ program to check we can buy product with given money or not
- Program to check we can reach leftmost or rightmost position or not in Python
- Program to check whether we can take all courses or not in Python
- Program to check whether we can unlock all rooms or not in python
- Program to check we can cross river by stones or not in Python
- Program to check we can form array from pieces or not in Python
- Python program to check whether we can pile up cubes or not
- Program to check whether we can get N queens solution or not in Python
- Program to check we can replace characters to make a string to another string or not in C++
- Program to check programmers convention arrangements are correct or not in Python
- Program to check we can visit any city from any city or not in Python
- Program to check whether we can convert string in K moves or not using Python
- Program to check we can reach at position n by jumping or not in Python
- C++ Program to check string can be reduced to 2022 or not
