# COMM3 - Editorial

EASY

### EXPLANATION

Try all 3 pairs of transceivers to see which ones can communicate directly. If at least 2 pairs can communicate directly then at least one transceiver can communicate directly with the other two so the answer is ‘yes’. Otherwise, if at most 1 pair can communicate directly then the answer is ‘no’. To determine if two transceivers located at (x1,y1) and (x2,y2) we simply check that (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) < = r * r. This is the same as checking that the distance between them is r, but we can avoid floating point computations this way. Note that the input numbers are small enough to ensure that the above expression only involves signed 32 bit integers.

### SETTER’S SOLUTION

Can be found here.

### TESTER’S SOLUTION

Can be found here.

this code is running right on code,compile&run but showing wrong answer on submission … please can someone tell what is wrong in this…

https://www.codechef.com/viewsolution/7569348

https://discuss.codechef.com/questions/4293/comm3-editorial/73419 @deeksha_garg.
You have not used sqrt() while calculating a,b and c which means they are already having unit sq. metre.
In following loop also you are squaring it so its unit becomes metre ^4 as compared to r whose power is metre^2.
Also, the logic is incorrect see setter’s solution . He has explained it nicely , you should be able to understand that!

Hi,

The following code is running right on my computer but is giving a wrong answer. Could you pl. explain the flaw?

https://www.codechef.com/viewsolution/9104921

Thank you,

#include<math.h>
#include
#include<stdio.h>
using namespace std;

struct point{
double x,y;
}p[3];

double calculate(struct point p1,struct point p2)
{
return sqrt(((p1.x-p2.x)(p1.x-p2.x))+((p1.y-p2.y)(p1.y-p2.y)));
}

main()
{
int t,i,ctr;
double len[3],maxlen;
cin>>t;
while(t–)
{
ctr=0;
cin>>maxlen;
for(i=0;i<3;++i)
{scanf("%f %f",&p[i].x,&p[i].y);}
i=0;
while(i<2)
len[i]=calculate(p[i],p[++i]);
len[2]=calculate(p[2],p[0]);
for(i=0;i<3;++i)
{
if(len[i]<=maxlen)
++ctr;
}
if(ctr>=2)
cout<<“yes\n”;
else
cout<<“no\n”;
}
}

This code is running fine in my compiler. However, it is showing wrong answer while submitting. Can someone please look into this?

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int r,x1,x2,x3,y1,y2,y3,count;
int d1,d2,d3;
for(int i=0;i<t;i++)
{
count=0;
r=sc.nextInt();
x1=sc.nextInt();
y1=sc.nextInt();
x2=sc.nextInt();
y2=sc.nextInt();
x3=sc.nextInt();
y3=sc.nextInt();

``````	    d1=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
d2=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
d3=(x3-x2)*(x3-x2)+(y3-y2)*(y3-y2);
if((d1<=(r*r)&&d2<=(r*r)) || (d1<=(r*r)&&d3<=(r*r)) || (d2<=(r*r)&&d3<=(r*r)))
System.out.println("Yes");
else
System.out.println("No");

}

}
``````

}

3 Likes

One thing that immediately leaps out is that your capitalisation of the answers is wrong: it should be

`yes` or `no`

not

`Yes` or `No`

2 Likes

Here is our complete solution to the problem in C++

#include<iostream
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int r,x1,y1,x2,y2,x3,y3;
cin>>r;
cin>>x1>>y1;
cin>>x2>>y2;
cin>>x3>>y3;
int d1=(x1-x2)(x1-x2)+(y1-y2)(y1-y2);
int d2=(x1-x3)(x1-x3)+(y1-y3)(y1-y3);
int d3=(x2-x3)(x2-x3)+(y2-y3)(y2-y3);
if(d1<=(rr) && d2<=(rr) || d1<=(rr) && d3<=(rr) || d3<=(rr) && d2<=(rr))
{
cout<<“yes”<<endl;
}
else{
cout<<“no”<<endl;
}
}
return 0;
}

Notebefore-
1)Using iostream as an header will consume less time than bits/stdc++.h.
2)Don’t input the numbers using cin in the same line since it gives compilation error due to the nature of input to the problem.
3)The mathematical formula for calculating the distance between the two points in coordinate geometry is—
D=√ (x2-x1)^2+(y2-y1)^2

1 Like

Guys My code is running correct on the compiler but when I submit , it shows error.
Please can someone tell me what is wrong . Here is the link ----------

https://www.codechef.com/viewsolution/48899621