uva 10670 Work Reduction(贪心)
题目大意:有tol的工作量,和要求达到的工作剩余量sur,然后是公司总数,对应每个公司提供两种服务,1、完成一个工作量,2.完成当前未完成工作量的一半(注意这里是tol的一半,不是tol - sur的一半), 当剩余工作量为奇数, 对模2四舍五入。现在给出每个公司的两种服务所需费用, 要求计算出每个公司单独完成工作量所花费的最少金额(剩余工作量必须为sur,输出按照金额大小,相同按照公司名字的字典序大小。
解题思路:贪心, 对于每个公司,比较当前单位工作量的花费金额,来决定选用哪种服务。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 105; struct company {
char name[N];
int one;
int half;
int value;
}tmp[N];
char str[N];
int tol, sur; bool cmp(const company &a, const company &b) {
if (a.value < b.value) return true;
else if (a.value > b.value) return false;
else
return strcmp(a.name, b.name) < 0;
} int count(int t, int h) {
int sum = tol, cur = 0;
while (sum != sur) {
int w = (sum + 1) / 2;
if (t * w > h && sum - w >= sur) {
sum -= w;
cur += h;
}
else {
sum--;
cur += t;
}
}
return cur;
} void handle(int cur) {
int len = strlen(str), cnt = 0, sex = 0;
for (int i = 0; i < len; i++) {
if (sex == 0 && str[i] != ':')
tmp[cur].name[cnt++] = str[i];
else if (str[i] == ':') {
tmp[cur].name[cnt++] = '\0';
sex++;
}
else if (sex == 1 && str[i] != ',')
tmp[cur].one = tmp[cur].one * 10 + str[i] - '0';
else if (str[i] == ',')
sex++;
else
tmp[cur].half = tmp[cur].half * 10 + str[i] - '0';
}
tmp[cur].value = count(tmp[cur].one, tmp[cur].half);
} int main() {
int cas, t = 1, n;
scanf("%d", &cas);
while (cas--) {
memset(tmp, 0, sizeof(tmp));
scanf("%d%d%d%*c", &tol, &sur, &n);
for (int i = 0; i < n; i++) {
gets(str);
handle(i);
} sort(tmp, tmp + n, cmp); printf("Case %d\n", t++);
for (int i = 0; i < n; i++)
printf("%s %d\n", tmp[i].name, tmp[i].value);
}
return 0;
}
uva 10670 Work Reduction(贪心)的更多相关文章
- 10670 Work Reduction (贪心 + 被题意坑了- -)y
Problem C: Work Reduction Paperwork is beginning to pile up on your desk, and tensions at the workpl ...
- UVa 10670 - Work Reduction
题目大意:对n份文件进行处理使其减少到m份,有l个机构可供选择.每个机构提供两种方案:每减少一份收费a元,或者减少到文件数量的一半收费b元.根据各个机构收取费用进行排序. 很直接的题目,直接进行模拟就 ...
- uva 1615 高速公路(贪心,区间问题)
uva 1615 高速公路(贪心,区间问题) 给定平面上n个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里得距离不超过D.(n<=1e5) 对于每个 ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- UVA 10718 Bit Mask 贪心+位运算
题意:给出一个数N,下限L上限U,在[L,U]里面找一个整数,使得N|M最大,且让M最小. 很明显用贪心,用位运算搞了半天,样例过了后还是WA,没考虑清楚... 然后网上翻到了一个人家位运算一句话解决 ...
- UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...
- UVA 12130 - Summits(BFS+贪心)
UVA 12130 - Summits 题目链接 题意:给定一个h * w的图,每一个位置有一个值.如今要求出这个图上的峰顶有多少个.峰顶是这样定义的.有一个d值,假设一个位置是峰顶.那么它不能走到不 ...
- UVA - 11134 Fabled Rooks[贪心 问题分解]
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to t ...
随机推荐
- echarts3相关的各种定制化
在我刚把项目中的echarts从2.x版本升级到echarts3.x,折腾老久,终于交付了项目的时候,echarts4又出来了,先不管,还是把我echarts3.x遇到的和formatter相关的问题 ...
- sass compass问题小结
1.中文注释编译报错Invalid GBK character的问题,找到ruby sass安装目录,如D:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\sass-3.4. ...
- Tasker to stop Poweramp control for the headset while there is an incoming SMS - frozen
If you usually like to use Poweramp or any other media player to enjoy the music with headset plugge ...
- http://bbs.chinaunix.net/thread-169061-1-1.html
http://bbs.chinaunix.net/thread-169061-1-1.html
- [MySql]锁表与解锁
摘要 为啥会出现锁表的情况?锁表会导致数据表的其他操作超时,频繁的插入修改查询很容易出现锁表的情况.如果遇到这种情况,临时的解决办法,可以通过下面的方式进行解锁.如果长期有效的解决,那么就需要优化项目 ...
- Spring-Bean配置-使用外部属性文件(转)
Spring-Bean配置-使用外部属性文件 所以可以通过@value注解获取配置文件的key-value,生成一个配置文件bean.用以在代码中直接使用bean的方式. •在配置文件里配置Bean时 ...
- arcgis andriod GeometryEngine使用
intersectionMenuItem.setChecked(true); showGeometry(GeometryEngine.intersection(inputPolygon1, input ...
- NodeJS学习资料合集
1. 官网 nodejs 2. How do I get started with Node.js,stackoverflow提问,收集非常多实用的网站 3. node-books.github收 ...
- ArcEngine 连接sql server sde
前言 本想在soe中进行sde for sqlserver数据获取.由于soe的调试不方便,为了测试的简便,先在桌面上写了个arcengine连接sde for sqlserver的程序,但是本以为是 ...
- 非常优秀的iphone学习文章总结!
This site contains a ton of fun tutorials – so many that they were becoming hard to find! So I put t ...