NewItemShop
SRM 515 · 2011-05-25 · by lyrically
Problem Statement
Lecette has information about her customers. The information is given as
When a customer comes to the shop, Lecette can choose to either accept or reject the offer. She cannot sell more than one sword to the same customer. Let's define S as the total amount of money that Lecette will get for all the swords sold during the day. Lecette will act in such a way that maximizes the expected value of S. Return this expected value.
Notes
- The returned value must have an absolute or relative error less than 1e-9.
Constraints
- swords will be between 1 and 24, inclusive.
- customers will contain between 1 and 24 elements, inclusive.
- Each element of customers will contain between 5 and 50 characters, inclusive.
- Each element of customers will be formatted as "T1,C1,P1 T2,C2,P2 ... TN,CN,PN", where Each Tj, Cj and Pj will be nonnegative integers without extra leading zeros.
- Each Tj will be between 0 and 23, inclusive.
- Each Cj will be between 1 and 100, inclusive.
- Each Pj will be between 1 and 100, inclusive.
- For each t, 0 <= t < 24, there will be at most one pair (i, j) such that the value of Tj in customers[i] is equal to t.
- In each element of customers, T1 < T2 < ... < TN will hold.
- In each element of customers, P1 + P2 + ... + PN will not exceed 100.
1
{ "8,1,80 16,100,11", "12,10,100" }
Returns: 19.0
The optimal strategy is as follows: At 08:00, Lecette should not sell the sword even if the first customer comes to the shop. At 12:00, the second customer surely comes. Then, If the first customer has come at 08:00, she should sell the sword to the second customer. Otherwise, she should not sell the sword to the second customer. She should sell it at 16:00 if possible. By this strategy, S will be 10 (80%) or 100 (11%) or 0 (9%).
2
{ "8,1,80 16,100,11", "12,10,100" }
Returns: 21.8
1
{ "0,90,25 2,90,25 4,90,25 6,90,25", "7,100,80" }
Returns: 90.0
3
{ "17,31,41 20,59,26 23,53,5", "19,89,79", "16,32,38 22,46,26", "18,43,38 21,32,7" }
Returns: 135.5121414
5
{ "1,1,10", "2,2,9", "3,3,8", "4,4,7", "5,5,6", "6,6,5", "7,7,4", "8,8,3", "9,9,2", "10,10,1" }
Returns: 2.1999744634845344
Submissions are judged against all 141 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class NewItemShop with a public method double getMaximum(int swords, vector<string> customers) · 141 test cases · 2 s / 256 MB per case