UVa 10026 Shoemaker's Problem (贪心)
来源:互联网 发布:域名搜索引擎注册 编辑:程序博客网 时间:2024/04/29 20:00
10026 - Shoemaker's Problem
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=967
Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ith 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 ith 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.
The 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.
The 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
143 41 10002 25 5
Sample Output
2 1 3 4
注意到:
1. 当规定时间相同时,应优先完成违约金多的工作。
2. 对于2 2和5 5这两份工作,先完成哪个都是一样的。
综上,应优先完成违约金/规定时间大的工作。
完整代码:
/*0.015s*/#include<cstdio>#include<algorithm>using namespace std;struct node{double k;int order;bool operator < (const node a)const{return k > a.k;}} job[1010];int main(void){int t, n;double x, y;scanf("%d", &t);while (t--){scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%lf%lf", &x, &y);job[i].k = y / x;job[i].order = i + 1;}sort(job, job + n);printf("%d", job[0].order);for (int i = 1; i < n; i++)printf(" %d", job[i].order);putchar('\n');if (t) putchar('\n');}return 0;}
- UVa 10026 Shoemaker's Problem 贪心
- UVA 10026 Shoemaker's Problem (贪心)
- uva 10026 Shoemaker's Problem 贪心
- UVa 10026 Shoemaker's Problem (贪心)
- uva - 10026 - Shoemaker's Problem(贪心)
- uva 10026 Shoemaker's Problem _贪心
- UVA - 10026 Shoemaker's Problem(贪心)
- UVA - 10026 Shoemaker's Problem 贪心
- UVA 10026-Shoemaker’s problem(贪心)
- Shoemaker's Problem - UVa 10026 贪心
- uva 10026 Shoemaker's Problem(贪心+排序)
- uva 10026 Shoemaker's Problem (贪心)
- UVA 10026 Shoemaker's Problem 鞋匠的难题 贪心+排序
- UVa 10026 - Shoemaker's Problem
- uva 10026 - Shoemaker's Problem
- uva 10026 - Shoemaker's Problem
- uva 10026 - Shoemaker's Problem
- uva 10026 Shoemaker's Problem
- linux驱动模块开机自动加载,以及应用程序开机自启动
- oracle数据库关于时间间隔的函数
- 排列组合之错排问题总结
- GetSystemTimes 获取CPU占用率
- spring factoryBean 和 beanFactory 的区别
- UVa 10026 Shoemaker's Problem (贪心)
- 【LeetCode】Integer to Roman & Roman to Integer解题笔记
- 华晨金杯X30 不走寻常路
- struts2 Caught exception while loading file struts-default.xml 的错误
- WinCE6.0 Camera驱动整体结构
- 查询数据库中表的大小情况。
- 记录一linux命令:xargs
- android 中View, Window, Activity, WindowManager,ViewRoot几者之间的关系
- 【OGNL表达式struts2标签“%,#,$”】