VolumeGuess
SRM 191 · 2004-04-24 · by Ishan
Problem Statement
You are given a
Notes
- Keep in mind, the volume of the largest box is irrelevant.
Constraints
- numberOfBoxes will be between 3 and 9, inclusive.
- queries will contain exactly numberOfBoxes*(numberOfBoxes-1)/2 elements.
- Every element of queries will be in the given format ("box1,box2,volume", quotes for clarity).
- Each element of queries will contain between 5 and 50 characters, inclusive.
- Each box1 will be an integer between 1 and numberOfBoxes, inclusive, with possible leading zeros.
- Each box2 will be an integer between 1 and numberOfBoxes, inclusive, with possible leading zeros.
- Each volume will be an integer between 1 and 500, inclusive, with possible leading zeros.
- queries will contain no duplicates, that is, no pair of boxes will be compared twice.
- No two boxes will have the same volume.
- ithBox will be between 1 and numberOfBoxes, inclusive.
- The given data will be consistent.
- The box numbered ithBox will not be one of the two largest boxes.
{"1,2,10","1,3,10","2,3,20"}
3
1
Returns: 10
If box 1 has volume 10, box 2 has volume 20 and box 3 has volume 30, we get the given data. Another possibility is box 1 has volume 10, box 2 has volume 30 and box 3 has volume 20. Another is box 1 has volume 10, box 2 has volume 45 and box 3 has volume 20. There are many possibilities (infinite in fact). However, in all of them box 1 has to have size 10.
{"1,02,10","2,3,010","1,3,20"}
3
2
Returns: 10
If box 1 has volume 20, box 2 has volume 10 and box 3 has volume 30, we get the given data. (Note that leading zeros are allowed.)
{"1,2,31","1,3,9","1,4,31","2,4,32","3,4,9","3,2,9"}
4
1
Returns: 31
One possibility is box 1 has volume 31, box 2 has volume 50, box 3 has volume 9 and box 4 has volume 32.
{"1,2,31","1,3,9","1,4,31","2,4,32","3,4,9","3,2,9"}
4
3
Returns: 9
Same situation as above, but asks for a different ithbox.
{"3,2,80","5,2,15","1,2,193","3,1,80","5,1,15","5,3,15","3,4,3","4,5,3","2,4,3","4,1,3"}
5
3
Returns: 80
Submissions are judged against all 48 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class VolumeGuess with a public method int correctVolume(vector<string> queries, int numberOfBoxes, int ithBox) · 48 test cases · 2 s / 256 MB per case