Computers
SRM 257 · 2005-08-08 · by dgoodman
Problem Statement
Create a class Computers that contains a method choices that takes four ints
as input: n (the number of processors), minDif (the smallest allowable difference between the
number of processors in different computers), minInComp (the minimum number
of processors that a computer is allowed to have), and amount (the number of computers we must
produce). The method returns a
Constraints
- n will be between 1 and 1000, inclusive.
- minDif will be between 5 and 1000, inclusive.
- minInComp will be between 1 and 1000, inclusive.
- amount will be between 1 and 1000, inclusive.
20 6 5 2 Returns: 4
The different ways in which we can produce the 2 computers are {5,15}, {6,14}, {7,13}, and {10,10}. Note that {4,16} would not be legal since a computer is not allowed to have less than 5 processors, and that {8,12} would not be legal because these two computers are different but do not differ by at least 6 processors.
100 500 400 1 Returns: 0
Since each computer must have at least 400 processors and we have only 100, it is not possible to build even 1 computer.
1000 5 5 10 Returns: 113420686168080
1000 5 1 10 Returns: 173961190219683
529 8 3 5 Returns: 14613709
Submissions are judged against all 84 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Computers with a public method long long choices(int n, int minDif, int minInComp, int amount) · 84 test cases · 2 s / 256 MB per case