PlatypusDuckAndBeaver
SRM 553 · 2012-06-05 · by vexorian
SRM 553 · 2012-06-05 · by vexorian · Simple Math, Simple Search, Iteration
Problem Statement
Problem Statement
Your friend the farmer liked to use the following method to count the number of beavers and ducks present on the farm: He would first find three int s webbedFeet, duckBills and beaverTails, representing the number of webbed feet, duck bills and beaver tails he could count and then he used those numbers to find the number of ducks and beavers on the farm. (A duck has one duck bill and two webbed feet. A beaver has one beaver tail and four webbed feet.)
The method worked great until he received news that there could be a platypus invasion on the farm. A platypus is a marvellous creature that has 4 webbed feet, a duck bill and a beaver tail. Our farmer is justifiably confused. Help him find out that his method is still useful. You are givenint s webbedFeet, duckBills and beaverTails that specify the number of webbed feet, duck bills and beaver tails the farmer has counted, respectively. Return the total number of animals (ducks, beavers, and platypuses) on the farm. The constraints guarantee that there will be exactly one solution.
The method worked great until he received news that there could be a platypus invasion on the farm. A platypus is a marvellous creature that has 4 webbed feet, a duck bill and a beaver tail. Our farmer is justifiably confused. Help him find out that his method is still useful. You are given
Constraints
- webbedFeet, duckBills and beaverTails will each be between 0 and 1000, inclusive.
- There will be exactly one way to assign the number of ducks, beavers and platypuses such that the total number of each specific kind of body part matches webbedFeet, duckBills and beaverTails, respectively.
Examples
0)
4 1 1 Returns: 1
If there is only one platypus, it will have 4 webbed feet, 1 beaver tail and 1 duck bill. Matching the description.
1)
0 0 0 Returns: 0
2)
10 2 2 Returns: 3
One platypus, one duck and one beaver.
3)
60 10 10 Returns: 20
10 ducks and 10 beavers.
4)
2 1 0 Returns: 1
127)
1000 500 0 Returns: 500
Largest result
Submissions are judged against all 138 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class PlatypusDuckAndBeaver with a public method int minimumAnimals(int webbedFeet, int duckBills, int beaverTails) · 138 test cases · 2 s / 256 MB per case