Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Wifi Routers problem solution

YASH PAL, 31 July 202417 February 2026
In this HackerEarth Wifi Routers problem solution, IIIT Hyderabad is planning to install Wifi Routers in the campus to make it fully Wifi-enabled. Now each Wifi Router can only transmit data to a user or another WiFi Router only if the distance between Router and the receiving user/router is not more than R.
 
Each Wifi Router has the same range R. A Wifi Router can get data from ground network or another Wifi Router. The aim here is that all the users get the data.
 
You have to find the minimal value of R that will ensure that all users get the data even if only one WiFi router is connected with ground network.
 
 
HackerEarth Wifi Routers problem solution

 

 

HackerEarth Wifi Routers problem solution.

#include <string> 
#include <assert.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string.h>
using namespace std;

int main()
{
int t;
cin >> t;
while(t--)
{
int flag[109][109]={};
int nn,mm,temp1,temp2;
cin >> nn >> mm;
if(nn>=1 && nn<=100);
assert(mm>=0 && mm<=100);
vector<int> x;
vector<int> y;
vector<int> c;
for(int i=0; i<nn; i++){
cin >> temp1 >> temp2;
assert(temp1>=0 && temp1<=100);
assert(temp2>=0 && temp2<=100);
if(flag[temp1][temp2]==1)
assert(-1>0);
flag[temp1][temp2]=1;
x.push_back(temp1);y.push_back(temp2);c.push_back(1);
}

for(int i=0; i<mm; i++){
cin >> temp1 >> temp2;
assert(temp1>=0 && temp1<=100);
assert(temp2>=0 && temp2<=100);
if(flag[temp1][temp2]==1)
assert(-1>0);
flag[temp1][temp2]=1;
x.push_back(temp1);y.push_back(temp2);c.push_back(0);
}
assert((int)c.size() == (nn+mm));
int n=(int)x.size();

int d[n][n];

for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
d[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);

for (int i=0; i<n; i++) if (c[i]==0)
for (int j=0; j<n; j++)
for (int k=0; k<n; k++)
d[j][k]=min(d[j][k], max(d[j][i], d[i][k]));

int sol=0;

for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
if (c[i]==0 && c[j]==1)
sol=max(sol, d[i][j]);
printf("%.6lfn",sqrt(sol));
}
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes