Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each i-th job, it is known the integer Ti (1 ≤ Ti ≤ 1000), the time in days it takes the shoemaker to finish the job. For each day of delay before starting to work for the i-th job, shoemaker must pay a fine of Si (1 ≤ Si ≤ 10000) cents. Your task is to help the shoemaker, writing a programm to find the sequence of jobs with minimal total fine.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

First line of input contains an integer N (1 ≤ N ≤ 1000). The next N lines each contain two numbers: the time and fine of each task in order.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

You programm should print the sequence of jobs with minimal fine. Each job should be represented by its number in input. All integers should be placed on only one output line and separated by one space. If multiple solutions are possible, print the first lexicographically.

Sample Input

1

4

3 4

1 1000

2 2

5 5

Sample Output

2 1 3 4

题链接:UVA10026 Shoemaker's Problem

问题简述:

裁缝要修理N双鞋子,每天只能修一双,每个鞋子有规定修的天数以及每延迟一天修要罚钱的数目,找出花费罚钱最少的修鞋顺序。

问题分析:

这是一个经典贪心法解决的问题,令fine=money/day,每天罚钱fine越大,就要越早修理,使得总罚钱最少。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA10026 Shoemaker's Problem */#include <bits/stdc++.h>using namespace std;const int N = 1000;
struct Job{int no;double day, money, fine;
} job[N];int cmp(Job a, Job b) {return fabs(a.fine - b.fine) > 0.00000001 ? a.fine > b.fine : a.no < b.no;
}int main()
{int t, n;scanf("%d", &t);while(t--) {scanf("%d", &n);for(int i = 0; i < n; i++) {scanf("%lf %lf", &job[i].day, &job[i].money);job[i].fine = job[i].money / job[i].day;job[i].no = i + 1;}sort(job, job + n, cmp);for (int i = 0; i < n - 1; i++)printf("%d ", job[i].no);printf("%d", job[n - 1].no);if (t)printf("\n\n");elseprintf("\n");}return 0;
}

UVA10026 Shoemaker's Problem【贪心】相关推荐

  1. UVA-10026 Shoemaker's Problem (贪心)

    题目大意:一个鞋匠,有n只鞋要修,修某只鞋的时间ti已知,某只鞋晚修一天要交的罚款fi也已知.现在让找个修鞋顺序使得罚款最少. 题目分析:本来想水一下这道题,没想到真的AC啦.后来又查的题解,找的解释 ...

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

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

  3. UVa11389 The Bus Driver Problem(贪心)

    问题:市中有n个司机,有n个早班路线和晚班路线.每个司机分配一个早班和晚班路线,如果一个司机的总行程路线超过d,超过的部分按每小时r元计算.问最小的加班费多少. 思路:贪心算法. 先以两个情况为例.早 ...

  4. UVa 10026 - Shoemaker's Problem

    题目大意:鞋匠有n个任务,第i个任务要花费ti天,同时第i个任务每耽误一天要有fi的罚金.求完成所有任务的最小罚金. 虽然知道是贪心,可是并不确定如何作贪心选择,只好"取经"了.. ...

  5. 【Gym 102893 L】The Firm Knapsack Problem (贪心)

    题目链接 题目大意 一个 01 背包问题,物品数 n≤105n\le 10^5n≤105 ,容量 W≤1012W\le 10^{12}W≤1012 .将体积上限放宽到 32W\frac{3}{2}W2 ...

  6. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  7. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  8. ICPC程序设计题解书籍系列之八:(美)斯基纳等:《挑战编程-程序设计竞赛训练手册》

    S书<挑战编程--程序设计竞赛训练手册>题目一览 1 Getting Started UVA100 POJ1207 HDU1032 The 3n + 1 problem[水题] - 海岛B ...

  9. ICPC程序设计题解书籍系列之六:吴永辉:《算法设计编程实验》

    第1章 Ad Hoc问题 POJ2661 HDU1141 ZOJ2545 UVA10916 Factstone Benchmark[Ad Hoc] UVA10037 Bridge[贪心] POJ257 ...

最新文章

  1. 股市币市:数据分析与交易所最新公告
  2. 动态规划之-----单调递增最长子序列(nyoj17)
  3. python大神作品_掌握了这24个顶级Python库,你就是大神!
  4. Qt新添加的类无法链接
  5. 使用Eclipse的Working Set管理项目
  6. linux composer使用php,记录linux下composer使用的坑爹过程
  7. 4复数与复变函数(四)
  8. java timer.schedule如何控制执行次数_Java 面试——JIT详解
  9. matlab希尔伯特变换,基于matlab的Hilbert变换详解
  10. VRRP在城域网中的应用
  11. cad怎么画立体图形教学_CAD画三维图中如何绘制三维实体
  12. 公式编辑器mathType中的公式在word中显示乱码的问题
  13. vue标签上自定义动态背景图片
  14. Idea使用系统应用打开md文件
  15. 各大互联网软件公司校招时间表大盘点
  16. mac 安装 Adobe CC XD
  17. Android权限说明
  18. 桌球歷史:削球、快攻、弧圈球
  19. OTA 电控信息安全
  20. 使用MyBatis-Plus 导致接口响应变慢的原因分析

热门文章

  1. jquery中ajax请求分类
  2. 600个开源iOS应用库
  3. android 蓝牙通信编程
  4. android应用开发全程实录-你有多熟悉listview? .
  5. 【转载】RPG模式研究——即时制与回合制战斗对比
  6. C#调用非托管Dll
  7. c语言代码先来先服务算法_C语言十大经典排序算法(动态演示+代码,值得收藏)...
  8. MySQL为啥不用平衡二叉树_MySQL的索引,为什么是B+而不是平衡二叉树
  9. idea启动Tomcat控制台乱码但是不报错
  10. 高阶java_Java高阶语法---final