Greedy.

证明:

Let's say we have job 1, 2, ..., n, and they have time and fine as t1, f1, t2, f2, ..., tn, fn

and they are in the order of t1/f1 <= t2/f2 <= t3/f3 <= ... <= tn/fn

So this is the objective schedule. Now we change 1 with m (1 < m <= n)

By the original order, we need pay fine as much as: F1 = t1 * (f2 + ... + fn) + t2 * (f3 + ... + fn) + ... + tm * (fm+1 + ... + fn) + R

By the new order, we need pay fine as much as: F2 = tm * (f1 + ... + fm-1 + fm+1 + ... + fn) + t1 * (f2 + ... + fm-1 + fm+1 + ... + fn) + ... + fm-1 * fm+1 + ... + fn) + R

F1 - F2 = (t1 + t2 + ... + tm-1) * fm - (tm * f1 + tm * f2 + ... + tm * fm-1)

As t1 * fm <= tm * f1, t2 * fm <= tm * f2, ..., tm-1 * fm <= tm * fm-1 F1 - F2 <= 0

So the original order is the best order.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h> using namespace std; /*
4.6.5
*/ struct Rec {
int time, cost, id;
Rec(int atime, int acost, int aid) : time(atime), cost(acost), id(aid) {}
}; bool camp(Rec r1, Rec r2) {
return r1.time * r2.cost < r1.cost * r2.time;
} int main() {
int TC = 0; cin >> TC;
bool blank = false;
for (int tc = 1; tc <= TC; tc++) {
int num = 0; cin >> num;
vector<Rec> recs;
for (int i = 0; i < num; i++) {
int time, cost; cin >> time >> cost;
recs.push_back(Rec(time, cost, i + 1));
} stable_sort(recs.begin(), recs.end(), camp); if (blank) {
cout << endl;
}
blank = true;
for (int i = 0; i < recs.size(); i++) {
if (i > 0) cout << " ";
cout << recs[i].id;
}
cout << endl;
}
return 0;
}

programming-challenges Shoemaker&#39;s Problem (110405) 题解的更多相关文章

  1. UVA 10026 Shoemaker&#39;s Problem

    Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can w ...

  2. BZOJ2298:[HAOI2011]problem a——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2298 https://www.luogu.org/problemnew/show/P2519 一次 ...

  3. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  4. UVA - 10239 The Book-shelver&#39;s Problem

    Description Problem D The Book-shelver's Problem Input: standard input Output: standard output Time ...

  5. codeforces 459D - Pashmak and Parmida&#39;s problem【离散化+处理+逆序对】

    题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...

  6. 湘潭大学1185 Bob&#39;s Problem

    Bob's Problem Accepted : 114   Submit : 589 Time Limit : 1000 MS   Memory Limit : 65536 KB 题目描写叙述 Bo ...

  7. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

  8. 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)

    洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...

  9. Lintcode399 Nuts & Bolts Problem solution 题解

    [题目描述] Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one m ...

随机推荐

  1. java中Collection 与Collections的区别

    1. Collection是集合类的一个顶级接口,其直接继承接口有List与Set 而Collections则是集合类的一个工具类/帮助类,其中提供了一系列静态方法,用于对集合中元素进行排序.搜索以及 ...

  2. Mysql怎么样避免全表扫描,sql查询优化

    对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引: 尝试下面的技巧以避免优化器错选了表扫描: 使用ANALYZE TABLE tbl_name为扫 ...

  3. [环境搭建] VS-Visual Studio-IIS Express 支持局域网訪问

    原创作品,转载请注明出处:http://blog.csdn.net/qiujuer/article/details/40350385 使用Visual Studio开发Web网页的时候有这种情况:想要 ...

  4. 拿到offer过后--大学最后时光最想做的那十件事

    昨天--2014.10.26,历史性的一刻,激动的签了欢聚时代(YY)的前端开发offer,工作地点是我喜欢的珠海(仅仅由于那边有我所向往的海还有自行车队,如今想想都乐开怀了,绕着海边骑单车的感觉真妙 ...

  5. 【MongoDB】深入了解MongoDB不可不知的十点

    一.对象ID的生成 每一个mongoDB文档那个都要求有一个主键.它在每一个集合中对全部的文档必须是唯一的.主键存放在文档_id字段中.由12个字符组成: 4c291856       238d3b  ...

  6. 黑马day15 文件上传&amp;apche的工具包

    1.肯定要导入apche的jar包 2.要使用的类的介绍.. 2.1DiskFileItemFactory  public DiskFileItemFactory(int sizeThreshold, ...

  7. android sudio 执行的中文是乱码解决方式

    1.File-->Setings-->查找file encodings 例如以下图 2.将 IDE Encoding .Project Encoding.Default encoding ...

  8. m_Orchestrate learning system---十四、数据表中字段命名规则

    m_Orchestrate learning system---十四.数据表中字段命名规则 一.总结 一句话总结:a.保证唯一 b.见名知意 1.注意php中的数组类函数和字符串类函数的前缀? 数组类 ...

  9. Linux就该这么学 20181004(第五章用户权限)

    参考链接https://www.linuxprobe.com/ Linux是一个多用户.多任务的操作系统,具有很好的稳定性与安全性,在幕后保障Linux系统安全的则是一系列复杂的配置工作.本章将 详细 ...

  10. AbstractQueuedSynchronizer中CAS的疑惑

    这段代码是AQS框架中将当前节点入队的操作. Node pred = tail; if (pred != null) { node.prev = pred; if (compareAndSetTail ...