MKTRNG-EDITORIAL

PROBLEM LINK: Click here

Contest: Hey Newbees, Here is Some Honey -ROUND 2

Author: Arefin Labib

Co-Author: Samia Rahman

Tester: Nazmus Sakib

Tester: Sanjida Akter

Tester: Redowan Ibrahim

DIFFICULTY:

Easy

PREREQUISITES:

Geometry

PROBLEM:

Sondesh is making a formation of triangles with the sticks filling the below criteria:
• All the triangles are same and congruent
• All the triangle connects to at least one common point
• Triangles will never overlap each other.
And it is also ensured that the formation is forming a regular polygon if at least a triangle could be made. You have given the number of triange in that formation and you have to calculate how many sticks have been used in that formation.

Quick Explanation:

If n=0 print -1

Else if n=1 print 3

Else if n=2 print 5

Else print 2*n

EXPLANATION:

Look at the criteria’s. It obviously should have focus ur mind to think like that, you will connect all the angular points to the midpoint of the polygon and will get all same, congruent, non-overlapping and having a common point triangle. For n=4, the figure can be like:
n-4
This is the formation when n=4 that means there are 4 triangles in that polygon and all the sticks are shown in different colour. So just count and you will get it there are 2*n triangle possible. Another example is given in the question statement.
But there are some exceptions. If n=2, The formation will be a Rhombus.
n-2

Do this formation disobey any criteria? There are more then one common point between the triangles.
Are you confused what it will be if n=3 ? Here is the formation.
n-3
If n=1, it is a simple triangle, and you know well, a triangle is a polygon.
And at last, if n=0, print -1.

TIME COMPLEXITY: O(1)

SOLUTIONS:

Python
for _ in range(int(input())):
    n=input()
    p=int(n)
    if p==0 or p==2:
        print("-1")
    elif p==1:
        print("3")
    else:
        print(2*p)
C++
//BISMILLAHIR RAHMANIR RAHIM
#include<bits/stdc++.h>
using namespace std;
int main()

{

    ll t,j,n;
    cin>>n;
    for(j=0; j<t; j++)
   {
        cin>>n;
        if(n==0)
            cout << "-1" << endl;
        else if(n==1)
            cout <<"3"<< endl;
        else if(n==2)
            cout << "-1" << endl;
        else
            cout << n*2 << endl;

    }
    return 0;
}
1 Like

I think n=4 is not possible because for that square, we can even choose the triangles formed by any of its diagonals. I think n=6 for a square

Please note that: Triangles will never overlap each other.

But aren’t we just considering one pair at a time?(i.e. isn’t sticks overlapping it’s equivalent condition?)

I did’nt get your words.

Sondesh is making a formation of triangles

she was forming triangle’s and after the formation created, she found that it was a polygon. So, while you are targeted for making triangles, you should’nt extend a stick to another triangle. But it can be a common arm of two different triangle.