- 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
Queries to check if it is possible to join boxes in a circle in C++
In this tutorial, we will be discussing a program to find queries to check if it is possible to join boxes in a circle.
For this we will be provided with a circle of boxes running from 1 to n. Our task is to find whether box i can be connected to box j with a rod without intersecting the previous rodes.
Example
#include <bits/stdc++.h> using namespace std; //checking if making a circle from boxes is possible void isPossible(int n, int q, int queryi[], int queryj[]) { int arr[50]; for (int i = 0; i <= n; i++) arr[i] = 0; for (int k = 0; k < q; k++) { int check = 0; if (queryj[k] < queryi[k]) { int temp = queryi[k]; queryi[k] = queryj[k]; queryj[k] = temp; } if (arr[queryi[k]] != 0 || arr[queryj[k]] != 0) check = 1; else if (queryi[k] == queryj[k]) check = 1; else { for (int i = 1; i < queryi[k]; i++) { if (arr[i] != 0 && arr[i] < queryj[k] && queryi[k] < arr[i]) { check = 1; break; } } if (check == 0) { for (int i = queryi[k] + 1; i < queryj[k]; i++) { if (arr[i] != 0 && arr[i] > queryj[k]) { check = 1; break; } } } } if (check == 0) { cout << "Possible" << endl; arr[queryi[k]] = queryj[k]; arr[queryj[k]] = queryi[k]; } else cout << "Not Possible" << endl; } } int main() { int size = 5; int q = 2; int queryi[] = { 3, 5 }; int queryj[] = { 1, 4 }; isPossible(size, q, queryi, queryj); return 0; }
Output
Possible Possible
- Related Articles
- Queries to check if it is possible to join boxes in a circles in C++ Program
- Is it possible to select text boxes with JavaScript?
- Check if it is possible to survive on Island in Python
- Is it possible to check if a String only contains ASCII in java?
- Is it possible in Android to check if a notification is visible or canceled?
- Check if it is possible to transform one string to another in Python
- Check if it is possible to sort the array after rotating it in Python
- Check if it is possible to create a polygon with a given angle in Python
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to create a polygon with given n sidess in Python
- Check if it is possible to return to the starting position after moving in the given directions in C++
- Check if it is possible to serve customer queue with different notes in Python
- Queries to check if substring[L…R] is palindrome or not in C++ Program
- Check if it is possible to rearrange rectangles in a non-ascending order of breadths in Python
- Check if it is possible to reach vector B by rotating vector A and adding vector C to its in Python

Advertisements