Geometry Forever

Fear no more, this is a problem of geometry! When Moyna was little, he had a math teacher named Shuk…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

#include <stdio.h>

int main() {
int A,B,sum;
scanf(“%d %d”,&A,&B);
sum=A+B;
printf(“%d\n”,sum-1);

return 0;

}

what’s wrong with this code?
#always correct in 1st case but wrong after 2nd case!

The sum of the lengths of any two sides of a triangle must be greater than the length of the third side. Not of the first two.
If the give lengths of two side are a and b and the third side is c then a + b > c , a + c > b and b + c > a. Your code will work for the first one but not for the others.

#include<stdio.h>

int main()
{
int A, B, count=0, C;
scanf(“%d %d”, &A, &B);
if(A>=1 && B<=100)
{
for(C=A-B; C<A+B; C++)
{
if(C>A-B && C<A+B)
{
count++;
}
}
printf(“%d\n”, count);
}
return 0;
}

now what’s the problem in this code?

I think this is a fault in the problem. As far as it says, there should be the values sides A and B given and we find the possible number of integer values of side C. But from your argument, it seems like the values of A and B are given and answers are checked by the values of B and C or whatsoever. Correct me if I’m wrong.

Actually I don’t understand what are you saying but it seems you didn’t understand what I meant. Suppose that, A = 5, B = 3. Accordingly to backbenchermmc’s code The answer should be 5+3-1 = 7 and the set of the answers should be {1, 2, 3, 4, 5, 6, 7}.
A+B=5+3=8 and it is greater than any of the value of the set
Now, this answer satisfies A+B>C
But there are two more conditions. A+C>B and B+C>A
Now, for the first value B+C = 3+1 = 4
Which isn’t greater then 5
So the actual set of answer is {3, 4, 5, 6, 7}
And the actual answer is 5

#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;

ll def(ll a, ll b) {
if(a>b) return a-b;
return b-a;
}

int main() {
ll a , b;
cin >> a >> b;
cout << (a+b) - (def(a,b)+1);
}

//Maybe it is the shortest method

The shortest solution that I provide is here:::

>     #include <bits/stdc++.h>
>     using namespace std;
> 
>     int main()
>     {
>         int a, b;
>         cin >> a >> b;
>         int minimum = min(a, b);
>         cout << (2 * minimum - 1) << endl;
>     }

Thank you all!

another possible answer is here:

#include
using namespace std;
int main()
{
int i,j,a,b;
cin>>a>>b;
i=min(a,b);
j=max(a,b);
cout<<(a+b)-((j-i)+1)<<endl;
return 0;
}

What is the problem?

#include<stdio.h>

int main()
{
int N,X;
int c=0;
scanf(“%d %d”,&N,&X);

for(int i=1;i<(N+X);i++){
	if (N<(i+X) && X<(i+N)){
	c++
	
	}
	
}
	printf("%d\n ",c);

return 0;

}

Hi Guys,

If two sides of a triangle are given the probale third side should
statify the following condition:

 - Side A + Side B > Side C 
 - Side A + Side C > Side B 
 - Side C + Side B > Side A
 - Area of the triangle > 0
    Area of the triangle = Math.sqrt(s * (s-Side A) * (s-Side B) * (s-Side C));
    s-value = (Side A + Side B + Side C)/2
    Reference: https://www.mathsisfun.com/geometry/herons-formula.html
   
FOR INSTANT
-----------

Side A = 3                                                                                                                               
Side B = 5                                                                                                                               

Side C	s-Value	Area                                                                                                             
  7 	 7.5 	6.49519052838329                                                                                                          
  6 	 7.0 	7.483314773547883                                                                                                         
  5 	 6.5 	7.1545440106270926                                                                                                        
  4 	 6.0 	6.0                                                                                                                       
  3 	 5.5 	4.14578098794425                                                                                                          

PROBABLE Side C = 3 4 5 6 7        


IN/OUTPUT SET
-------------
1 1	1
3 5	3 4 5 6 7
12 15	4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
56 66	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 45 46 47 48 49 50 51 52 
	53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 
	74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 
	95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 
	112 113 114 115 116 117 118 119 120 121

There could be multiple values of Side C in most cases. And, these sets of 
outcome satify all pre-condition required to find Side C. The output sets need
to be corrected!
	
SAMPLE CODE IN JAVA
--------------------
import java.util.Scanner;
import java.lang.Math; 

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sideA = sc.nextInt();
		int sideB = sc.nextInt();
		int sumAB = sideA + sideB;
		double s=0F, area=0F;
		int arr[] = new int[sumAB];
		int count = 0;
		if(0<sideA && sideA<= 100 && 0<sideB && sideB<=100){
		    for(int i=sumAB; i>=1; i--){
		        s = (sumAB+i)/2F;
		        area = Math.sqrt(s * (s-sideA) * (s-sideB) * (s-i));
		        arr[count] = 0;
		        if(area > 0F){
		            arr[count] = i;
		        }
		        count++;
		    }
		    for(int j=count-1; j>=0; j--){
		        if(arr[j]>0){
		            if(((sideA + sideB) > arr[j]) && ((sideA + arr[j]) > sideB) && ((arr[j] + sideB) > sideA)){
		                System.out.println(arr[j]);
		            }
		        }
		    }
		}
		//The output sets are incorrect!!!
	}
}

I hope things are understood and the output sets will be corrected.
Thanks.