UVA - 10026 Shoemaker's Problem
2016-11-20 15:40
405 查看
题目大意:鞋匠有许多鞋要做,但每次只能做一双鞋,别的鞋子在开始之前都需要赔偿延期的费用,给出每个单子需要的天数和延期一天所需要赔的费用,输出赔偿最少的情况的顺序。
解题思路:贪心,考虑只有两双鞋的顺序,若 a b 那么所需费用就是 b 的费用×a 的天数,若 b a 则是 a 的费用×b 的天数,比较两种费用选择费用少的那种顺序。
解题思路:贪心,考虑只有两双鞋的顺序,若 a b 那么所需费用就是 b 的费用×a 的天数,若 b a 则是 a 的费用×b 的天数,比较两种费用选择费用少的那种顺序。
#include<iostream> #include<cstdio> #include<cmath> #include<string.h> #include<stdlib.h> #include<algorithm> #include<stack> using namespace std; const int MAXN = 1000+5; struct node { int id; int t; int s; }num[MAXN]; bool cmp(node a, node b) { return a.s * b.t > b.s * a.t; } int main() { int T, n; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) { num[i].id = i + 1; scanf("%d%d", &num[i].t, &num[i].s); } sort (num, num+n, cmp); for (int i = 0; i < n-1; i++) { printf("%d ", num[i].id); } printf("%d\n", num[n-1].id); if (T) printf("\n"); } return 0; }
相关文章推荐
- UVa 10026 Shoemaker's Problem
- uva10026 - Shoemaker's Problem
- UVa10026 - Shoemaker's Problem
- uva 10026 Shoemaker's Problem
- Uva 10026 Shoemaker's Problem
- UVa Problem 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 贪心
- From:UVA, 10026 Problem B : Shoemaker's Problem
- uva 10026 Shoemaker's Problem(贪心+排序)
- 10026 - Shoemaker's Problem
- 10026 - Shoemaker's Problem
- UVA 10026 Shoemaker's Problem
- UVA 10026 Shoemaker's Problem (贪心)