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. 我一不小心把ubuntu里的ps这样的命令删掉了,应该怎么重装呢

    sudo apt-get --reinstall install procps    

  2. ASP.NET-datatable转换成list对象

    #region 讲DataTable转换为List对象 /// <summary> /// 利用反射将DataTable转换为List<T>对象 /// </summar ...

  3. POJ 3128

    置换的开方. 看看Pan的那篇集训论文.此处,可以想到,开方时,由于gcd(l,2),则必然有若是循环长度为偶数,必定是成对出现的.若是奇数,既可以是偶数也可以是奇数,因为,通过二次方后,循环长度为偶 ...

  4. 一起talk C栗子吧(第一百一十二回:C语言实例--线程同步概述)

    各位看官们,大家好.上一回中咱们说的是线程间通信的样例,这一回咱们说的样例是:线程同步.闲话休提,言归正转.让我们一起talk C栗子吧! 看官们,提到同步.我想大家都不陌生,由于我们在前面章回中介绍 ...

  5. HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场

    開始对点搜索,直接写乱了.想了想对边搜索,尽管复杂度高.剪枝一下水过去了. 代码: #include<cstdio> #include<iostream> #include&l ...

  6. 算法 - 求一个数组的最长递减子序列(C++)

    //************************************************************************************************** ...

  7. 使用ViewPager实现广告滑动效果

    效果图:               watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSk1DNjAx/font/5a6L5L2T/fontsize/400/ ...

  8. scikit-learn:3.5. Validation curves: plotting scores to evaluate models

    參考:http://scikit-learn.org/stable/modules/learning_curve.html estimator's generalization error can b ...

  9. linux 应用软件集合

    史上最全面的Linux应用软件大集合 | 博客水木 1. 生产力 Linux 桌面的便利贴:Stickynotes sudo add-apt-repository ppa:umang/indicato ...

  10. Qt开发环境的搭建

    首先讲讲为什么要用Qt这个东东吧!用了以后才知道,这门语言真的很不错,我权当把它当成了类库来用,Linux本身的C语言编程是很烦的,比如说串口编程,虽说C编程也不难,但是使用Qt这种封装的类库来操作的 ...