

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum possible intersection by moving centers of line segments in C++
In this tutorial, we will be discussing a program to find maximum possible intersection by moving centers of line segments
For this we will be provided with the center of three line segments and their length. Our task is to move their center by K distance to increase the length of intersection region.
Example
#include <bits/stdc++.h> using namespace std; //finding maximum intersection int max_intersection(int* center, int length, int k) { sort(center, center + 3); if (center[2] - center[0] >= 2 * k + length) { return 0; } else if (center[2] - center[0] >= 2 * k) { return (2 * k - (center[2] - center[0] - length)); } else return length; } int main() { int center[3] = { 1, 2, 3 }; int L = 1; int K = 1; cout << max_intersection(center, L, K); }
Output
1
- Related Questions & Answers
- How do I find the intersection of two line segments in Matplotlib?
- C++ Program to get maximum area of rectangle made from line segments
- Centers of a tree
- Check if two line segments intersect
- Maximum number of parallelograms that can be made using the given length of line segments in C++
- Maximum points of intersection n circles in C++
- Maximum points of intersection n lines in C++
- Maximum number of segments of lengths a, b and c in C++
- Klee’s Algorithm (Length Of Union Of Segments of a line) in C++
- Find all disjointed intersections in a set of vertical line segments in JavaScript
- Represent a Given Set of Points by the Best Possible Straight Line in C++
- Program to find number of sets of k-non-overlapping line segments in Python
- Maximum number of segments that can contain the given points in C++
- Maximum Possible Sum of Products in JavaScript
- How do you create line segments between two points in Matplotlib?
Advertisements