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 ...
随机推荐
- CDOJ 1402 三角形棋盘上的博弈游戏 状压DP
三角形棋盘上的博弈游戏 题目连接: http://mozhu.today/#/problem/show/1402 Description 柱爷有天上课无聊,于是和同桌卿学姐一起下一种奇特的棋: 棋盘如 ...
- Codeforces 505A Mr. Kitayuta's Gift 暴力
A. Mr. Kitayuta's Gift time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Caffe2(3)----下载现成的模型并使用
Caffe2训练好的模型可在Model Zoo下载,下载的命令很简单,接下来以下载和使用squeezenet为例,进行简单说明. 1.浏览可下载的模型 已有模型都放在github上,地址:https: ...
- 趁热打铁学node
前言 不废话直接官网下载安装. windows安装很简单,双击ok. 完成后命令行输入node -v. 会提示版本号,说明安装成功(Node.js 还自动附带安装了 npm,类似ruby的gem). ...
- Git_创建与合并分支
在版本回退里,你已经知道,每次提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线,在Git里,这个分支叫主分支,即master分支.HEAD严格来说不是指向提交,而 ...
- ISO7816 (part 1-3) asynchronous smartcard information
http://java.inf.elte.hu/java-1.3/javacard/iso7816.txt ============================================== ...
- ARCGIS将WGS84坐标投影到高斯平面
将WGS84坐标投影到平面,一般採用的是UTM(通用横轴莫卡托投影).该方式多用于美国地区,而我国多用北京54和西安80高斯克吕格投影坐标.假如我们想把影像採用高斯克吕格投影到在平面上,而ARCGIS ...
- mr
大数据技术 —— MapReduce 简介 本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 1.概要很多计算在概念上很直观,但由于输入数据很大, ...
- SQL:表格创建学习笔记
CREATE TABLE 语法 CREATE TABLE "table_name"("column 1" "data type for column ...
- C++语言笔记系列之十六——赋值兼容规则&多继承的二义性
1.赋值兼容规则 (1)派生类对象能够给基类对象赋值,这样的情况下派生类对象将从基类继承的成员的值赋值给一个基类对象:可是不同意将一个基类的对象赋值给一个派生类. (2)能够将派生类对象的地址赋给基类 ...