Hey Newbees, Here is Some Honey [Round 2] - PA for Stick counting

https://www.codechef.com/BLAS2020/problems/MKTRNG

can someone share the solution if possible in python

1 Like

Its simple. Can be solved by drawing and analysis.
For n(no of triangles)=1, we need 3 sticks,
n=2, we need 5 sticks
n=3, we need 6 sticks
n=4, we need 8 sticks
n=5, we need 10 sticks
n=6, we need 12 sticks
n=7, we need 14 sticks
So, basically for n>=3, we need (n*2) sticks.
Obviously for n<=0, not possible, hence β-1β according to problem.

In C++14 the code is,

#include
using namespace std;

int main()
{
int t,n;
cin>>t;
while (tβ)
{
cin>>n;
if (n<=0)
cout<<"-1"<<endl;
else if (n==1)
cout<<β3β<<endl;
else if (n==2)
cout<<β5β<<endl;
else if (n>=3)
cout<<n*2<<endl;
}
return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
void solve()
{
ll N;cin>>N;
if(N==0)cout<<"-1\n";
else if(N==1 || N==2)cout<< 2N + 1 <<β\nβ;
else cout<< 2
N <<β\nβ;
}
int main(void)
{
int T; cin>>T;
while(Tβ){solve();}exit(0);
}

My answer for only wrong because of n=3 how its 6 . Please explain .
mine came 7

like this

1 Like

thank you so much ritik. got it

why canβt input 3 be trapezium with 3 triangle

1 Like

anyone solved min and max?
what is the optimal method to find out whether there exists an element at some position which is minimum in corresponding row and maximum in corresponding column at the same position?

a regular polygon is a polygon that is equiangular but trpezium has outer unequal sides .thats why

βAll the triangle connects to at least one common pointβ

This is my solution but got wrong answer for it.
Python 3
t = int(input())
for i in range(t):
n = int(input())
if n <= 0 :
print(-1)
elif n == 1 :
print(3)
elif n == 2 :
print(5)
elif n == 3 :
print(7)
else:
print(n*2)