ArticleDirectory
- Sample Input
- Sample output
Problem C: Work ction
Paperwork is beginning to pile up on your desk, and tensions at the workplace are starting to mount. your boss has threatened to fire you if you don't make any progress by the end of the day. you currently haveNUnits of paperwork on your desk, and your boss demands that you have exactlyMUnits of paperwork left by the end of the day.
The only hope for you now is to hire help. There are varous agencies which offer paperwork limit ction plans:
For$They will reduce your paperwork by one unit.
For$ BThey will reduce your entire paperwork by half (rounding down when necessary ).
Note that work can never be forced CED to less than 0.
Your task now is to produce a sorted table of agency names and their respective minimum costs to solve your workload problem.
the first line of input consists of a single positive integer representing the number of cases to follow. each case begins with three positive integers separated by spaces: n -your starting workload, m -your target workload, and L -the number of work functions ction agencies available to you, (1 <= m <= n <= 100000, 1 <= L <= 100 ). the next L lines have the format "[ agency name ] : A , B ", where A and B are the rates as described above for the given agency. (0 <= A, B <= 10000) the length of the agency name will be between 1 and 16, and will consist only of capital letters. agency names will be unique.
For each test case, print "case X", with X being the case number, on a single line, followed by the table of agency names and their respective minimum costs, sorted in non-decreasing order of minimum costs. sort job agencies with identical minimum costs in alphabetical order by agency name. for each line of the table, print out the Agency name, followed by a space, followed by the minimum required cost for that agency to solve your problem.
Sample Input
2100 5 3A: 1, 10B: 2, 5C: 3,11123 1122 5b: 50,300 A: 1, 1000c: 10, 10d: 1, 50e:
Sample output
Case 1C 7b 22a 37 Case 2E 0a 1D 1C 10b 50
Gilbert Lee
# Include <iostream> # Include < String ># Include <Algorithm> Using Namespace STD; Const Int Maxn = 101 ; Struct Agent { String Name; Int Money ;}; agent Ag [maxn]; Bool Mycomp (agent A, Agent B ){ If (A. Money! = B. Money) Return A. Money < B. money; Else Return A. Name < B. Name ;} Int Main (){ // Freopen ("in.txt", "r", stdin ); Int Cases, N, M, L; String S; CIN > Cases; For ( Int Count = 1 ; Count <= Cases & CIN> N> m> L; count ++ ){ Int Temp = N; Getline (CIN, S ); For ( Int I = 0 ; I <L & Getline (CIN, S); I ++, n = Temp ){ Int Pos1 = S. Find ( ' : ' ), Pos2 = S. Find ( ' , ' ); AG [I]. Name = S. substr ( 0 , Pos1 ); Int Sum1 = 0 , Sum2 = 0 ; For (Int I = pos1 + 1 ; I <pos2; I ++ ) {Sum1 * = 10 ; Sum1 + = S [I]- ' 0 ' ;} For ( Int I = pos2 + 1 ; I <S. Length (); I ++ ) {Sum2 * =10 ; Sum2 + = S [I]- ' 0 ' ;} Int Mysum = 0 ; While (N> M ){ If (N> = 2 * M & sum2 <= sum1 * (N-N/ 2 ) {Mysum + = Sum2; n /= 2 ;} Else If (N> = 2 * M & sum2> sum1 * (N-N/ 2 ) {Mysum + = Sum1 * (N-N/ 2 ); N /= 2 ;} Else If (N < 2 * M) {mysum + = Sum1 * (N- M); n = M ;} // Cout <"mysum:" <mysum <"N:" <n <"\ n "; } Ag [I]. Money = Mysum;} Sort (AG, AG + L, mycomp); cout <" Case " <Count < " \ N " ; For ( Int J = 0 ; J <L; j ++ ) Cout <Ag [J]. Name < " " <Ag [J]. Money < " \ N " ;}}
Simple question.