-
Notifications
You must be signed in to change notification settings - Fork 0
/
To and Fro.txt
44 lines (23 loc) · 896 Bytes
/
To and Fro.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
The Guardians of the Galaxy have just landed on Earth.
There are N cities in a row numbered from 1 to N.
The cost of going from a city with number i to a city with number j is the remainder when (i+j) is divided by (n+1).
The Guardians want to visit every city but in the minimum cost. What is the minimum cost that will be incurred?
Problem Constraints
1 <= N <= 10000000
Input Format
A single integer N denoting the number of cities.
Output Format
Minimum cost to be able to travel to each city
Example Input
3
Example Output
1
Example Explanation
Tour would be 1 -> 3 -> 2.
...............Algorithm...........................
1 n 2 n-1 3 n-2 if you observe some pattern then you will find that this will give our optimal answer.because as try to make i+j to n+1 as much as possible
.
int Solution::solve(int A) {
// that will take 0(n^2).
return (A-1)/2;
}