
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 Articles
- How do I find the intersection of two line segments in Matplotlib?
- C++ Program to get maximum area of rectangle made from line segments
- What is the disadvantage in comparing line segments by mere observation?
- 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++
- Centers of a tree
- Check if two line segments intersect
- Two line segments are congruent if_________.
- Klee’s Algorithm (Length Of Union Of Segments of a line) in C++
- Maximum length of segments of 0’s and 1’s in C++
- Maximum number of segments of lengths a, b and c in C++
- Find the number of line segments in the given figure."\n
- Can a polygon have intersecting line segments?
- Maximum Possible Sum of Products in JavaScript

Advertisements