304 North Cardinal St.
Dorchester Center, MA 02124

# Obstacle Course CodeChef Solution

## Obstacle Course CodeChef Solution in C++17

``````#include<stdio.h>
#include<math.h>
//using namespace std;
#define S(X) ((X)*(X))
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
double d[600];
double x[600],y[600];
int done[600];
int main()
{
int T,i,n,r,R;
int id;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&r,&R);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);

for(i=0;i<n;i++)
{
d[i]=sqrt( S(x[i])+S(y[i]) )-r;
done[i]=0;
}

done[n]=0;
d[n]=R-r;
while(1)
{
id=-1;

for(i=0;i<=n;i++)
if(!done[i] && (id==-1 || d[id]>d[i]))
id = i;
if(id==n)
break;

done[id]=1;

for(i=0;i<n;i++)
if(!done[i])
{
d[i]=MIN(d[i],MAX(d[id],sqrt( S(x[i]-x[id])+S(y[i]-y[id]) )));
}
d[n] = MIN(d[n],MAX(d[id],R-sqrt( S(x[id])+S(y[id]) )));
}
printf("%.3lf\n",d[n]);
}
return 0;
} ``````

## Obstacle Course CodeChef Solution in C++14

``````#include<stdio.h>
#include<math.h>
//using namespace std;
#define S(X) ((X)*(X))
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
double d[600];
double x[600],y[600];
int done[600];
int main()
{
int T,i,n,r,R;
int id;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&r,&R);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);

for(i=0;i<n;i++)
{
d[i]=sqrt( S(x[i])+S(y[i]) )-r;
done[i]=0;
}

done[n]=0;
d[n]=R-r;
while(1)
{
id=-1;

for(i=0;i<=n;i++)
if(!done[i] && (id==-1 || d[id]>d[i]))
id = i;
if(id==n)
break;

done[id]=1;

for(i=0;i<n;i++)
if(!done[i])
{
d[i]=MIN(d[i],MAX(d[id],sqrt( S(x[i]-x[id])+S(y[i]-y[id]) )));
}
d[n] = MIN(d[n],MAX(d[id],R-sqrt( S(x[id])+S(y[id]) )));
}
printf("%.3lf\n",d[n]);
}
return 0;
} ``````

## Obstacle Course CodeChef Solution in C

``````#include<stdio.h>
#include<math.h>
//using namespace std;
#define S(X) ((X)*(X))
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
double d[600];
double x[600],y[600];
int done[600];
int main()
{
int T,i,n,r,R;
int id;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&r,&R);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
for(i=0;i<n;i++)
{
d[i]=sqrt( S(x[i])+S(y[i]) )-r;
done[i]=0;
}
done[n]=0;
d[n]=R-r;
while(1)
{
id=-1;
for(i=0;i<=n;i++)
if(!done[i] && (id==-1 || d[id]>d[i]))
id = i;
if(id==n) break;
done[id]=1;
for(i=0;i<n;i++)
if(!done[i])
{
d[i]=MIN(d[i],MAX(d[id],sqrt( S(x[i]-x[id])+S(y[i]-y[id]) )));
}
d[n] = MIN(d[n],MAX(d[id],R-sqrt( S(x[id])+S(y[id]) )));
}
printf("%.3lf\n",d[n]);
}
return 0;
}``````

## Obstacle Course CodeChef Solution in JAVA

``````
import java.util.*;
import java.io.*;
import java.math.*;

public class Main implements Runnable {

public void solve() throws IOException {
int testCases = nextInt();
StringBuffer sb = new StringBuffer("");
for (int test = 0; test < testCases; test++) {
double r = nextDouble();
double R = nextDouble();
int N = nextInt();
double[] x = new double[N];
double[] y = new double[N];
for (int i = 0; i < N; i++) {
x[i] = nextDouble();
y[i] = nextDouble();
}
//print(x);
//print(y);
double[][] dist = new double[N + 2][N + 2];
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
dist[i][j] = dist[j][i] = hypot(x[i] - x[j], y[i] - y[j]);
}
//print(dist[i]);
}
for (int i = 0; i < N; i++) {
dist[N][i] = dist[i][N] = hypot(x[i], y[i]) - r;
}
for (int i = 0; i < N; i++) {
dist[N + 1][i] = dist[i][N + 1] = R - hypot(x[i], y[i]);
}
dist[N][N + 1] = dist[N + 1][N] = R - r;
boolean[] visited = new boolean[N + 2];
double[] d = new double[N + 2];
Arrays.fill(d, 1e9);
d[N] = 0;
//print(d);
for (int k = 0; k < N + 2; k++) {
double min = 2e9;
int ind = 0;
for (int i = 0; i < N + 2; i++) {
if (d[i] < min && !visited[i]) {
min = d[i];
ind = i;
}
}
visited[ind] = true;
for (int i = 0; i < N + 2; i++) {
double dIndI = dist[ind][i];
if (min > dIndI) {
dIndI = min;
}

if (dIndI < d[i]) {
d[i] = dIndI;
}
}
}

System.out.printf("%.3f\n", d[N + 1]);
}
System.out.print(sb);
}

double hypot(double x, double y) {
return Math.sqrt(x * x + y * y);
}

void print(Object... obj) {
for (Object o : obj) {
System.out.println(o);
}
}

void print(int[] a) {
System.out.println();
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}

void print(double[] a) {
System.out.println();
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}

void print(char[][] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}

void print(boolean[][] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}

//-----------------------------------------------------------
public static void main(String[] args) {
new Main().run();
}

public void run() {
try {
tok = null;
solve();
in.close();
} catch (IOException e) {
System.exit(0);
}
}

public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
}
}

public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}

public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}

public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
StringTokenizer tok;
}``````
##### Obstacle Course CodeChef Solution Review:

In our experience, we suggest you solve this Obstacle Course CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Obstacle Course CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Obstacle Course CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!