UVa 10670 - Work Reduction
题目大意:对n份文件进行处理使其减少到m份,有l个机构可供选择。每个机构提供两种方案:每减少一份收费a元,或者减少到文件数量的一半收费b元。根据各个机构收取费用进行排序。
很直接的题目,直接进行模拟就好了。其中对A、B两种方案的选择使用贪心策略。
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 100+10 struct Agency
{
char name[];
int cost;
};
Agency agency[MAXN]; bool cmp (const Agency& a, const Agency& b)
{
if (a.cost != b.cost) return a.cost < b.cost;
else return strcmp(a.name, b.name) < ;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
//freopen("out", "w", stdout);
#endif
int T;
scanf("%d", &T);
for (int kase = ; kase <= T; kase++)
{
int n, m, l;
scanf("%d%d%d", &n, &m, &l);
getchar();
for (int i = ; i < l; i++)
{
int cnt = ;
char ch = getchar();
while (isupper(ch))
{
agency[i].name[cnt++] = ch;
ch = getchar();
}
agency[i].name[cnt] = '\0';
int a, b;
scanf("%d,%d", &a, &b);
getchar();
agency[i].cost = ;
int remain = n;
while (remain > m)
{
int half = remain / ;
if (half < m)
{
agency[i].cost += (remain - m) * a;
remain = m;
}
else
{
int t = a * (remain - half); // the cost reducing from remain to half with A
if (t < b) agency[i].cost += t;
else agency[i].cost += b;
remain = half;
}
}
}
sort(agency, agency+l, cmp);
printf("Case %d\n", kase);
for (int i = ; i < l; i++)
printf("%s %d\n", agency[i].name, agency[i].cost);
}
return ;
}
不过在读取名字的while循环中如果使用 while (ch = getchar() && isupper(ch)) 就会出问题,不知道为什么...
UVa 10670 - Work Reduction的更多相关文章
- uva 10670 Work Reduction(贪心)
题目连接:10670 - Work Reduction 题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1.完成一个工作量,2.完成当前未完成工作量 ...
- 10670 Work Reduction (贪心 + 被题意坑了- -)y
Problem C: Work Reduction Paperwork is beginning to pile up on your desk, and tensions at the workpl ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- UVA 12501 Bulky process of bulk reduction ——(线段树成段更新)
和普通的线段树不同的是,查询x~y的话,给出的答案是第一个值的一倍加上第二个值的两倍一直到第n个值的n倍. 思路的话,就是关于query和pushup的方法.用一个新的变量sum记录一下这个区间里面按 ...
- Lattice Reduction (LLL) 算法C代码实现
废话不多说,大名鼎鼎的Lenstra-Lenstra-Lovasz(LLL) 算法.实现参考论文:Factoring Polynomials with Rational Coefficients, 作 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- php 连接 mssql sql2008
摘要 sql server 2008 1.下载微软提供的dll 下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=20098 p ...
- 链表基础 HDU1267
基础的链表,模拟一下就好了...就签个到
- MySQL解决"is marked as crashed and should be repaired"故障
具体报错如下: Table '.\Tablename\posts' is marked as crashed and should be repaired 提示说论坛的帖子表posts被标记有问题,需 ...
- UIView的alpha、hidden、opaque 深入
转载自:http://blog.csdn.net/wzzvictory/article/details/10076323 UIView的这几个属性让我困惑了好一阵子,通过翻看官方文档和stackove ...
- ios复制到剪贴板
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...
- input输入框和 pure框架中的 box-sizing 值问题
在使用pureCSS框架的时候,遇到一个问题. input输入框,我给他们设置了宽度和padding值,我发现,在火狐和谷歌上面发现,增加padding值并不会影响最终的宽度,而在IE6 7下则会影响 ...
- pe and elf
http://staff.ustc.edu.cn/~sycheng/sst/exp_crack/ELF.pdf https://refspecs.linuxbase.org/elf/TIS1.1.pd ...
- PHP 领域模型与数据库映射文章
1. http://blog.csdn.net/happen_zhang/article/details/12761747 2. http://blog.csdn.net/hguisu/article ...
- OpenStack - liberty CentOS 7
OpenStack私有云部署 Controller Node: em1(10.6.17.11),em2() Computer Node: em1(10.6.17.12),e ...
- (简单) POJ 2253 Frogger,Dijkstra。
Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Fro ...