Original question:
Paperwork is beginning to pile up on your desk, and tensions at the workplace was starting to mount. Your boss has threatened to fire if you don't make any progress by the end of the day. You currently has N units of paperwork on your desk, and your boss demands so you have exactly M units of paperwork Lef T by the end of the day. The only hope-hire help. There is various agencies which offer paperwork reduction
Plans:
for A They would reduce your paperwork by one unit.
for B They would reduce your entire paperwork by half (rounding if necessary).
Note that the work can never is reduced to less than0.
Your task now-produce a sorted table of agency names and their respective minimum costs to solve Your workload probl Em.
Input
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 reduction
Agencies available to you, (1≤m≤n≤100000, 1≤l≤100).
The next L lines has the format ' agency Name:a,b ', where A and B is the rates as described above for the given agency. (0≤a,b≤10000). The length of the agency name would be between 1 and, and would consist only for capital letters. Agency names would be unique.
Output
For each test case, print ' Case X ', with X being the case number, on a, 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 on 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
Agency to solve your problem.
Sample Input
2
100 5 3
a:1,10
b:2,5
c:3,1
1123 1122 5
b:50,300
a:1,1000
c:10,10
d:1,50
e:0,0
Sample Output
Case 1
C 7
B 22
A 37
Case 2
E 0
A 1
D 1
C 10
B 50
Effect:
You have n files, now you need to help you finish n-m, there are a total of L helper, each helper to help you work there are two ways, one is to complete a document and charge a copy of the price, the other is to help you finish half of the remaining documents, and charge the corresponding price. Now ask each helper to spend the least amount of money to complete the n-m portion of the price is how much, the output when the cost per helper from small to large output. If the cost is the same, it is output by the size of the name.
#include <bits/stdc++.h> using namespace std;
FStream in,out;
struct agencies {string name;
int one;
int half;
int cost;
};
Agencies ag[101];
int CMP (const agencies &A,CONST agencies &b) {if (a.cost!=b.cost) return a.cost<b.cost;
else return a.name<b.name;
} int main () {Ios::sync_with_stdio (false);
int case;
int n,m,l,k=0,pn,pm;
cin>>case;
string S;
StringStream SS;
while (case--) {cin>>n>>m>>l;
for (int i=1;i<=l;++i) {ss.clear ();
cin>>s;
Pn=s.find (': ', 0);
Pm=s.find (', ', 0);
Ag[i].name=s.substr (0,PN);
Ss<<s.substr (pn+1,pm-pn-1);
ss>>ag[i].one;
Ss.clear ();
Ss<<s.substr (Pm+1,s.size ()-pm-1);
ss>>ag[i].half;
ag[i].cost=0;
} for (int i=1;i<=l;i++) {int tmp=n;
while (tmp>m) {int t=tmp%2? TMP/2+1:TMP/2;
if (t*ag[i].one>ag[i].half&&tmp-t>=m) {tmp-=t;
Ag[i].cost+=ag[i].half;
} else {ag[i].cost+= (tmp-m) *ag[i].one;
Tmp=m;
}}} sort (ag+1,ag+1+l,cmp);
cout<< "Case" <<++k<<endl;
for (int i=1;i<=l;i++) cout<<ag[i].name<< "" <<ag[i].cost<<endl;
} return 0;
}
Answer:
First enter the output to be processed. Next compare two scenarios, if the price of the scheme is halved, and one completes the file until half of the price is consumed. Halve if the scheme is cost-effective and halved by more than or equal to M. If the first time can not be halved, then the reduction of the file after half of the way is certainly not cost-effective, so the remaining documents will be used in one copy of the way to complete.