SNAPE - Editorial

Problem Link: contest, practice

Difficulty: Cakewalk

Pre-requisites: Geometry, Implementation

Problem:

We are given two numbers A and B. Our task is to determine the minimal and the maximal possible value of number C thus exists a non-obtuse triangle with the lengths of the sides equal to A, B and C.

It’s also guaranteed, that A < B.

Explanation:

It was the easiest problem of the contest.

Since A < B, the only angles, that could be obtuse, are the angles between sides A and B or A and C.

So, the minimal possible value of C is reached when the angle between sides A and C is right(equals to 90 degrees).

Also, the maximal possible value of C is reached when the angle between sides A and B is right(equals to 90 degrees).

The first value Cmin = sqrt( B2 - A2 );

The second value Cmax = sqrt( B2 + A2 ).

The total complexity is O(1) per testcase.

Setter’s Solution: link

Tester’s Solution: link

1 Like

we can use hypot(a,b) when finding c max, as it takes care of overflows.

#include <stdio.h>
#include<math.h>
int main()
{
int ls,base,t;
scanf("%d",&t);
double rs ,x,y;
while (t–)
{
x=0;y=0;rs=0;
scanf("%d %d",&base,&ls);
rs=sqrt(lsls+basebase);
y=sqrt(lsls-basebase);
printf("%f %f",y,rs);
}
return 0;
}

My code giving wrong answer…can anyone explain?
#include<stdio.h>
#include<math.h>
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int b,ls;
float min,max;
scanf("%d%d",&b,&ls);

min=sqrt((lsls)-(bb));
max=sqrt((lsls)+(bb));
printf("%f%f\n",min,max);
}
return 0;
}

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

int main() {
	int T;
	cin>>T;
	while(T--) {
		int B, LS;
		double min{0}, max{0};
		cin>>B>>LS;
		min = sqrt(LS * LS - B * B);
		max = sqrt(LS * LS + B * B);
		cout<<min<<" "<<max<<endl;
		
	}
	return 0;
}