- 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

# Final radiations of each Radiated Stations in C++ Program

Suppose there are N stations in the straight line. Each of them has same non-negative power of radiation power. Every station can increase the radiation power of its neighboring stations in the following way.

Suppose the station i with radiation power R, will increase (i – 1)th station’s radiation power, by R-1, (i - 2)th station’s radiation power by R-2, and will increase (i + 1)th station’s radiation power, by R-1, (i + 2)th station’s radiation power by R-2. So on. So for example, if the array is like Arr = [1, 2, 3], then the output will be 3, 4, 4. The new radiation will be [1 + (2 – 1) + (3 - 2), 2 + (1 – 1) + (3 - 1), 3 + (2 – 1)] = [3, 4, 4]

The idea is simple. For each station i increases the radiation of neighboring stations as mentioned above, up to when the effective radiation becomes negative.

## Example

#include <iostream> using namespace std; class pump { public: int petrol; int distance; }; int findStartIndex(pump pumpQueue[], int n) { int start_point = 0; int end_point = 1; int curr_petrol = pumpQueue[start_point].petrol - pumpQueue[start_point].distance; while (end_point != start_point || curr_petrol < 0) { while (curr_petrol < 0 && start_point != end_point) { curr_petrol -= pumpQueue[start_point].petrol - pumpQueue[start_point].distance; start_point = (start_point + 1) % n; if (start_point == 0) return -1; } curr_petrol += pumpQueue[end_point].petrol - pumpQueue[end_point].distance; end_point = (end_point + 1) % n; } return start_point; } int main() { pump PumpArray[] = {{4, 6}, {6, 5}, {7, 3}, {4, 5}}; int n = sizeof(PumpArray)/sizeof(PumpArray[0]); int start = findStartIndex(PumpArray, n); if(start == -1) cout<<"No solution"; else cout<<"Index of first petrol pump : "<<start; }

## Output

Index of first petrol pump : 1

- Related Questions & Answers
- Find the final radiations of each Radiated Stations in C++
- What is Effective Isotropic Radiated Power (EIRP)?
- Find the Number of Stopping Stations using C++
- Which are cleanest railway stations in India?
- Program to find final states of rockets after collision in python
- What are the types of stations for the HDLC Protocol?
- What are the effects of Variable Load on Power Stations?
- Explain final class and final method in PHP.
- C++ program to find the Sum of each Row and each Column of a Matrix
- Program to get final position of moving animals when they stops in Python
- Program to Find Out the Maximum Final Power of a List in Python
- Final Value Theorem of Laplace Transform
- Final Value Theorem of Z-Transform
- Java program to check occurrence of each character in String
- Java program to check occurrence of each vowel in String