题意:鞋匠一口气接到了不少生意,但是做鞋需要时间,鞋匠只能一双一双地做,根据协议每笔生意如果拖延了要罚钱。

给出每笔生意需要的天数和每天的罚钱数,求出最小罚钱的排列顺序。

只要按罚款/天数去从大到小排序,如果比例一样就按序号排序(要求字典序)。

解释我就不献丑了,附上Staginner大神的证明:

对于为什么贪心策略是这个样子的,我们不妨拿相邻的两个事件a、b来说明一下。由于a、b之后的事件是固定的,所以我们无论排成ab还是排成ba后面部分的损失都是固定的,那么损失的差别主要来源于究竟是排成ab还是排b成a。排ab的损失为ta*fb,排ba的损失为tb*fa,那么如果ta*fb<tb*fa,我们就排成ab,这样可以得到fa/ta>fb/tb,推而广之,就得到了我们的贪心策略。

代码:

 /*
* Author: illuz <iilluzen@gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10026.cpp
* Lauguage: C/C++
* Create Date: 2013-08-25 20:11:52
* Descripton: UVA 10026 Shoemaker's Problem, sort + struct
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL; /****** TEMPLATE ENDS ******/ const int MAXN = 1002;
struct Deal {
int no;
double pri;
int day;
friend bool operator < (const Deal& a, const Deal& b) {
if (a.pri != b.pri) return a.pri > b.pri;
else return a.no < b.no;
}
} d[MAXN]; int main() {
int t, n, m;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
rep(i, n) {
d[i].no = i + 1;
scanf("%d%d", &d[i].day, &m);
d[i].pri = (double)m / (double)d[i].day;
};
sort(d, d + n);
printf("%d", d[0].no);
repu(i, 1, n) printf(" %d", d[i].no);
printf("\n");
if (t) printf("\n");
}
return 0;
}

UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序的更多相关文章

  1. uva 10026 Shoemaker's Problem(排序)

    题目连接:10026 Shoemaker's Problem 题目大意:有一个鞋匠接了n双要修的鞋子, 修每双鞋需要d天,每推迟一天修将亏损val元,问按什么样的顺序修鞋可以保证损失最少,如果有多种情 ...

  2. uva 10026 Shoemaker's Problem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. uva 10026 Shoemaker's Problem _贪心

    题意:鞋匠现在有n个工作要做,每个工作要x天,没延迟一天需要付款y,鞋匠每天只能做一个工作,问使得鞋匠最少赔款的工作顺序. 思路:工作和工作之间排序,如果a.value*b.day>b.valu ...

  4. (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)

    /* * UVA_10026.cpp * * Created on: 2013年10月10日 * Author: Administrator */ #include <iostream> ...

  5. UVA 10026 Shoemaker&#39;s Problem

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

  6. UVa 101 The Blocks Problem Vector基本操作

    UVa 101 The Blocks Problem 一道纯模拟题 The Problem The problem is to parse a series of commands that inst ...

  7. 【暑假】[深入动态规划]UVa 1380 A Scheduling Problem

     UVa 1380 A Scheduling Problem 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=41557 ...

  8. UVA - 524 Prime Ring Problem(dfs回溯法)

    UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  9. uva 10837 - A Research Problem(欧拉功能+暴力)

    题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p−1; ...

随机推荐

  1. Spring Batch 批处理框架介绍

    前言 在大型的企业应用中,或多或少都会存在大量的任务需要处理,如邮件批量通知所有将要过期的会员,日终更新订单信息等.而在批量处理任务的过程中,又需要注意很多细节,如任务异常.性能瓶颈等等.那么,使用一 ...

  2. vim segment fault when i upgrade to macOS Mojave 103_PollServerReady

    系统升级到 macOS Mojave, vim插件YouCompleteMe出错. Vim: Caught deadly signal SEGV Error detected while proces ...

  3. AES advanced encryption standard

    // advanced encryption standard // author: karl malbrain, malbrain@yahoo.com typedef unsigned char u ...

  4. IntelliJ IDEA部署tomcat时Edit Configuration无artifact选项

    IntelliJ使用 ##使用IntelliJ IDEA配置web项目时,选择Edit Configration部署Tomcat的Deployment可能会出现以下情况: 导致新手部署过程中摸不着头脑 ...

  5. systemtap 用户态调试

    #include <stdio.h> int main( void) { ; a=fun(,); printf("%d\n",a); } int fun(int a,i ...

  6. 使用Enum.TryParse()实现枚举的安全转换

    在项目中,有时候会用到领域枚举和DTO枚举的映射和转换.有一个现实的问题是:如果领域枚举项发生变化,而DTO枚举项没有及时更新,这样会造成映射不上的问题.那么,如何避免此类问题呢? 先看领域枚举和DT ...

  7. git 分支管理策略 与 物理实现 --author by阮一峰 & 小鱼

    -------------------------下面是阮一峰博士的git branch 逻辑结构图示---------------------------------------------- 如果 ...

  8. AlertView动画

    AlertView动画 效果 源码 https://github.com/YouXianMing/Animations // // AbstractAlertView.h // Animations ...

  9. 使用 NSPropertyListSerialization 持久化字典与数组

    NSPropertyListSerialization The NSPropertyListSerialization class provides methods that convert prop ...

  10. jsonConfig使用方法

    1.先编写jsonConfig的初始化代码 private JsonConfig jsonConfig; public action构造方法() { jsonConfig = new JsonConf ...