Determine the position of the third person on regular N sided polygon | C ++ implementation of above approach ; Function to find out the number of that vertices ; Another person can 't stand on  vertex on which 2 children stand. ; calculating minimum jumps from each vertex . ; Calculate sum of jumps . ; Driver code ; Calling function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int vertices ( int N , int A , int B ) { int position = 0 ; int minisum = INT_MAX ; int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i == A i == B ) continue ; else { int x = abs ( i - A ) ; int y = abs ( i - B ) ; sum = x + y ; if ( sum < minisum ) { minisum = sum ; position = i ; } } } return position ; } int main ( ) { int N = 3 , A = 1 , B = 2 ; cout << " Vertex ▁ = ▁ " << vertices ( N , A , B ) ; return 0 ; }