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:否则 做减法也行,对题意无影 ...
随机推荐
- mysql sql灵活运用
1.mysq获取表的字段及属性 SELECT * FROM information_schema.COLUMNS WHERE table_name = 'item_url'; 2.正则表达式 SELE ...
- windows 安装mysql的时候最后执行一直停留在Write configuration file
出现原因:MySQL安装路径出现中文,特殊字符.或是重新安装MySQL后经常遇到.前者是路径不允许出现中文名称,后者是由于卸载不干净. 我就是因为重新安装了MySQL,卸载不干净,才会导致之后这个错误 ...
- http://www.itpub.net/thread-1778530-1-1.html
http://www.itpub.net/thread-1778530-1-1.html
- 交叉编译 小米路由器mini 的 python(MIPS)
看了很多文章,要么说的是用opkg安装python,要么说的是小米路由器的交叉编译,就是没有mini的.学习了这篇文章(http://me.deepgully.com/post/56389167868 ...
- hdu4666Hyperspace
http://acm.hdu.edu.cn/showproblem.php?pid=4666 先看一个求曼哈顿的帖子http://www.cnblogs.com/lmnx/articles/24797 ...
- hadoop2.2编程: SequenceFileWritDemo
import java.io.IOException; import java.net.URI; import org.apache.hadoop.fs.FileSystem; import org. ...
- [HDU 1565+1569] 方格取数
HDU 1565 方格取数(1) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- CSS3中动画属性transform、transition 和 animation
CSS3中和动画有关的属性有三个 transform.transition 和 animation.下面来一一说明: transform 从字面来看transform的释义为改变,使 ...
- spring3 mvc使用注解方式时,不能扫描jar包里面的类
使用eclipse export工具时选中Add directory entries可以解决.
- C#.NET 打印连续纸高度动态变化(基于长江支流的金质打印通)
问题是这样的,打印机使用的是卷筒的连续纸,要打印的内容因为数据行数不同,高度会有变化.这时如果能在打印时动态改变纸张大小(其实只改变高度即可)当然是最好的选择. 我使用了网上久负盛名的[长江支流]的“ ...