Letter Writer
PROBLEM :
LOBO is a letter writer and he is working in shop near post office. He has to write two types of letters which are:
Corporate Letters: 12 letters of this type can be written in an hour.
Informal Letters: 10 letters of this type can be written in an hour.
You are to help him to save time. Given N number of letters, print the minimum number of hours he needs to put for combination of both the letters, so that no time is wasted.
Input:
The first line will contain T denoting number of test cases. Then T test cases follow . Each test case will have an integer N.
Output:
For each test case in a new line , print the minimum number of hours LOBO needs to write the combination of both the letters. If it is NOT possible, print "-1".
Constraints:
1=T=100
1=N=150
Example
Input:
2
33
36
Output:
-1
3
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<limits.h>
int Letter_Writer(int ) ;
int min(int ,int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Letter_Writer(no)<<endl ;
}
return 0;
}
int Letter_Writer(int no)
{
int i ;
int temp[no+1] ;
if(no<10||no==11)
return -1 ;
for(i=0;i<=no;i++)
temp[i]=INT_MAX ;
temp[10]=1 ;
temp[12]=1 ;
for(i=13;i<=no;i++)
{
temp[i]=min(temp[i-10],temp[i-12]) ;
if(temp[i]!=INT_MAX)
temp[i]++ ;
}
if(temp[no]==INT_MAX)
return -1 ;
return temp[no] ;
}
int min(int a,int b)
{
return a<b?a:b ;
}
---------------------------------------------------------------------------------
LOBO is a letter writer and he is working in shop near post office. He has to write two types of letters which are:
Corporate Letters: 12 letters of this type can be written in an hour.
Informal Letters: 10 letters of this type can be written in an hour.
You are to help him to save time. Given N number of letters, print the minimum number of hours he needs to put for combination of both the letters, so that no time is wasted.
Input:
The first line will contain T denoting number of test cases. Then T test cases follow . Each test case will have an integer N.
Output:
For each test case in a new line , print the minimum number of hours LOBO needs to write the combination of both the letters. If it is NOT possible, print "-1".
Constraints:
1=T=100
1=N=150
Example
Input:
2
33
36
Output:
-1
3
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
#include<limits.h>
int Letter_Writer(int ) ;
int min(int ,int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Letter_Writer(no)<<endl ;
}
return 0;
}
int Letter_Writer(int no)
{
int i ;
int temp[no+1] ;
if(no<10||no==11)
return -1 ;
for(i=0;i<=no;i++)
temp[i]=INT_MAX ;
temp[10]=1 ;
temp[12]=1 ;
for(i=13;i<=no;i++)
{
temp[i]=min(temp[i-10],temp[i-12]) ;
if(temp[i]!=INT_MAX)
temp[i]++ ;
}
if(temp[no]==INT_MAX)
return -1 ;
return temp[no] ;
}
int min(int a,int b)
{
return a<b?a:b ;
}
---------------------------------------------------------------------------------
Comments
Post a Comment