Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1890
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1890
Putting Plates on the Tuk-tuks
By Marcio T. I. Oshiro, Universidade de São Paulo Brazil
Timelimit: 1
The tuk-tuk (ตุ๊กตุ๊ก), also known as "auto rickshaw", is a popular form of transportation in Thailand. In order to distinguish tuk-tuks from the other types of vehicles, the Phuket administration decided to create a new license plate system for them. Phuket's tuk-tuk fleet has been growing rapidly, mostly due to tourism, one of the most important economic activities in the province. The administration plans the new system to meet the demand for distinct license plates for the next 42 years.
A license plate system is defined by two numbers, C and D. A license plate in this system is a string formed by C consonants followed by D digits. A license plate cannot be empty (no consonant and no digit).
In the Thai alphabet there are 44 consonants and 10 digits. However, since the symbols of some consonants are too much alike, the administration decided to use only 26 consonants, whose symbols were considered sufficiently distinguishable.
To guarantee an appropriate supply of tuk-tuks for the contestants in the ICPC World Finals in 2016, Phuket's administration would like to know the number of distinct license plates it is possible to generate with a given license plate system.
Input
The first line of the input has an integer T corresponding to the number of instances.
Each instance is formed by a single line containing the integers C (0 ≤ C ≤ 6) and D (0 ≤ D ≤ 9), the number of consonants and digits, respectively, in a license plate system.
Output
For each instance, print a line with the amount of distinct license plates that can be generated by the corresponding system. The answer is guaranteed to be smaller than 231.
Input Sample | Output Sample |
3 0 6 2 4 0 0 |
1000000 6760000 0 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
typedef unsigned uint;
inline uint power(uint, uint);
int main(int argc, char **argv)
{
uint n, x ,y;
scanf("%d", &n);
while (n--)
{
scanf("%d %d", &x, &y);
if (!x && !y)
puts("0");
else if (!x)
printf("%u\n", power(10, y));
else if (!y)
printf("%u\n", power(26, x));
else
printf("%u\n", power(10, y) * power(26, x));
}
return 0;
}
uint power(uint a, uint b)
{
uint ans = 1;
while (b--)
ans *= a;
return ans;
}
Copy The Code &
Try With Live Editor
Input
0 6
2 4
0 0
Output
6760000
0
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int c, d;
int cases;
cin >> cases;
while (cases--)
{
cin >> c >> d;
if (c == 0 && d == 0) cout << 0 << '\n';
else
{
ll ans = 1;
while (c) {ans *= 26; --c;}
while (d) {ans *= 10; --d;}
cout << ans << '\n';
}
}
}
Copy The Code &
Try With Live Editor
Input
0 6
2 4
0 0
Output
6760000
0