10670 Work Reduction (贪心 + 被题意坑了- -)y
Problem C: Work Reduction
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 have N units of paperwork on your desk, and your boss demands that you have exactly M units of paperwork left by the end of the day.
The only hope for you now is to hire help. There are various agencies which offer paperwork reduction plans:
For $A they will reduce your paperwork by one unit.
For $B they will reduce your entire paperwork by half (rounding down when necessary).
Note that work can never be reduced 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 reduction 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
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
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int t, n, m, l; struct Work {
char name[20];
int a, b;
int value;
} w[105]; int cmp(Work aa, Work bb) {
if (aa.value != bb.value)
return aa.value < bb.value;
if (strcmp(aa.name, bb.name) < 0)
return 1;
else
return 0;
} void solve(int nn) {
int num = n;
while (num / 2 >= m) {
if (w[nn].b < (num -num / 2) * w[nn].a)
w[nn].value += w[nn].b;
else
w[nn].value += w[nn].a * (num - num / 2);
num /= 2;
}
w[nn].value += (num - m) * w[nn].a;
}
int main() {
int Case = 1;
scanf("%d", &t);
while (t --) {
memset(w, 0, sizeof(w));
scanf("%d%d%d%*c", &n, &m, &l);
for (int i = 0; i < l; i ++) {
char sb; int j = 0;
while ((sb = getchar()) != EOF && sb != ':') {
w[i].name[j ++] = sb;
}
w[i].name[j] = '\0';
scanf("%d%*c%d%*c", &w[i].a, &w[i].b);
}
for (int i = 0; i < l; i ++) {
solve(i);
}
sort(w, w + l, cmp);
printf("Case %d\n", Case ++);
for (int i = 0; i < l; i ++)
printf("%s %d\n", w[i].name, w[i].value);
}
return 0;
}
10670 Work Reduction (贪心 + 被题意坑了- -)y的更多相关文章
- uva 10670 Work Reduction(贪心)
题目连接:10670 - Work Reduction 题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1.完成一个工作量,2.完成当前未完成工作量 ...
- UVa 10670 - Work Reduction
题目大意:对n份文件进行处理使其减少到m份,有l个机构可供选择.每个机构提供两种方案:每减少一份收费a元,或者减少到文件数量的一半收费b元.根据各个机构收取费用进行排序. 很直接的题目,直接进行模拟就 ...
- hdu 5038 水题 可是题意坑
http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数 这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心 If not all ...
- hdu 6034 贪心模拟 好坑
关键在排序!!! 数组间的排序会超时,所以需要把一个数组映射成一个数字,就可以了 #include <bits/stdc++.h> using namespace std; typedef ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- codeforces 1020 C Elections(枚举+贪心)
题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路 ...
- AC_Dream 1224 Robbers(贪心)
题意:n个抢劫犯分别抢到的金钱是k1, k2, k3,...,一共得到的金钱是m, 但是在分钱的时候是按照x1/y, x2/y, x3/y,....的比例进行分配的!这样的话 一些抢劫犯就会觉得不公平 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- HDU4647+贪心
/* 贪心. 题意:给定一些点 一些边 点和边都有价值.现在A B 选点.求A-B的maxVal 思路:分割边.边的1/2分给两个端点. 如果这两个点被同一个人取,则ok:否则 做减法也行,对题意无影 ...
随机推荐
- iOS8定位问题
正文:主要解决iOS8以前能定位,但是在iOS8时候无法定位的问题 在iOS8以前,我们的GPS定位是在用户设置的里面显示的是总是使用,但是在iOS8以后,苹果修改了这部分授权,你需要多加入2个pli ...
- Bootstrap 与 ASP.NET MVC 4 不使用 NuGet Package 笔记
转自 http://www.mytecbits.com/microsoft/dot-net/bootstrap-with-asp-net-mvc-4-step-by-step 单位最近做了一个Boot ...
- 使用js为html元素动态添加class
<ul id="root"> <li>1</li> <li>2</li> <li>3</li> ...
- jquery script
http://tech.it168.com/a2012/0206/1307/000001307783_all.shtml http://blog.csdn.net/lyatzhongkong/arti ...
- loadrunner http协议put模式脚本编写
web_submit_data("rest", "Action=http://www.test.com/111ojhjh.do", "Method=P ...
- [Unity菜鸟] Mecanim 系统遇到的问题
1. 给角色添加一个Animator组件和New State,运行后,摆出这种奇怪的姿势 这是因为没有把动画片段赋给New State,可以看到此时的New State为空,把Idle片段拖进去就好了 ...
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-006- 使用thymeleaf(TemplateResolver、SpringTemplateEngine、ThymeleafViewResolver、th:include、th:object、th:field="*{firstName}")
一.在Spring中使用thymeleaf的步骤 1.配置 In order to use Thymeleaf with Spring, you’ll need to configure three ...
- Ember.js demo4
<!DOCTYPE html> <html> <head> <meta name="description" content=" ...
- C#中的OLEDB连接2
在通过ADO对Excel对象进行连接时(此时Excel则认为是一个数据源),需要配置对Excel数据源对应的连接串,这个连接串中包括了Provider信息(其实类似对数据库进行连接操作时,都需要指定连 ...
- 【HDOJ】5564 Clarke and digits
DP+快速矩阵幂.注意base矩阵的初始化,不难. /* 5564 */ #include <iostream> #include <string> #include < ...