PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4
Setter: [Utkarsh Gupta(utkarsh_adm | CodeChef User Profile for Utkarsh Gupta | CodeChef)
Tester: Abhinav Sharma, Aryan
Editorialist: Lavish Gupta
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef bought N items from a shop. Although it is hard to carry all these items in hand, so Chef has to buy some polybags to store these items.
1 polybag can contain at most 10 items. What is the minimum number of polybags needed by Chef?
EXPLANATION:
1 polybag can contain at most 10 items. Chef has N items.
If N is a multiple of 10, then Chef needs to use \frac{N}{10} polybags to carry all these items. However, if N is not a multiple of 10, then Chef will need \frac{N}{10} + 1 polybags. Here, \frac{N}{10} denotes integer division.
For example, if N = 20, Chef will need \frac{20}{10} = 2. If N = 24, then Chef will need \frac{24}{10} + 1 = 2 + 1 = 3 polybags.
The above statement can be concisely written as - Chef will need \left \lceil{\frac {N} {10}}\right \rceil polybags.
Tip for beginners
Suppose we want to find the value \left \lceil{\frac {N} K}\right \rceil for some given N and K. There are two ways to do this:
First way is to make two cases depending on whether N is divisible by K or not, just like we saw above.
Another concise way is to observe the fact that \left \lceil{\frac {N} K}\right \rceil = \frac{N+K-1}{K}. This can be directly used to find the value without writing if conditions.
TIME COMPLEXITY:
O(1) for each test case.
SOLUTION:
Editorialist's Solution
#include<bits/stdc++.h>
#define ll long long
using namespace std ;
int main()
{
ll t;
cin >> t ;
while(t--)
{
int n;
cin >> n ;
cout << (n+9)/10 << '\n' ;
}
return 0;
}