uva10026 - Shoemaker's Problem(贪心)

题目:10026 - Shoemaker‘s Problem

题目大意:有个鞋匠在同一天接到了一堆的生意。可是他每天只能做一双鞋,给出做每双鞋需要的时间和推辞做鞋的赔偿。问怎样合理的分配才能使得赔偿最小。

解题思路:鞋子编号  要花的时间  需要的赔偿(每天)

1                    1                100

2                    5                  4

这样的两双鞋有两种安排:

做完1再做2      赔偿  1 * 4;

做完2再做1      赔偿   5 * 100;

所以应该将时间/赔偿小的鞋子先做。

代码:

#include <stdio.h>
#include <algorithm>
using namespace std;

const int N = 1005;

struct Shoe {

	int i;
	int t;
	int f;
}s[N];

int cmp (const Shoe &a, const Shoe &b) {return a.t * b.f < b.t * a.f;}

int main () {

	int t;
	scanf ("%d", &t);

	int n;
	while (t--) {

		scanf ("%d", &n);
		for (int i = 0; i < n; i++) {

			scanf ("%d%d", &s[i].t, &s[i].f);
			s[i].i = i + 1;
		}

		sort (s, s + n, cmp);

		for (int i = 0; i < n; i++) {

			if (i == n - 1)
				printf ("%d\n", s[i].i);
			else
				printf ("%d ", s[i].i);
		}
		if (t)
			printf ("\n");
	}
	return 0;
}

uva10026 - Shoemaker's Problem(贪心)

时间: 2024-11-03 06:01:33

uva10026 - Shoemaker's Problem(贪心)的相关文章

[题解]UVA10026 Shoemaker&#39;s Problem

链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=967 描述:要做n双鞋子,第 i 双鞋子要做Ti天,每天消耗Si的钱(当前正在做第 i 双鞋子时不耗钱).求在最少消耗钱的情况下做鞋子的顺序. 思路:贪心 明显是一个排序的模型,然后我们就思考顺序怎么确定.考虑当前两双鞋子a和b,它们的顺序对它们前后的鞋子都没有影响,它们所创造的影响仅仅

uva 10026 Shoemaker&#39;s Problem(贪心+排序)

虽然是个水题,但是在一些细节上wa了几次,好像不支持'\b'退格符号,我用在了输出空格那,结果wa了...白白 wa了几次...题意是看的题解..今天只写了两道题,速度有点慢,得加快了,以后得先认真读懂题目,题目读懂了 就相当于做出来一半然后仔细动脑想想,有想法了再敲,不能盲目的做题.另外,热烈祝贺今天c++ primer看到 了100页 思路: 这道题是让给的数据是每件工作需要做的天数和每耽误一天所需要的费用,让求一个序列使得付费最小,如果有相同答 案把字典树最小的输出...输出的是序号,该件

UVa 10026 - Shoemaker&#39;s Problem

题目:一个鞋匠接到很多任务,每个任务有一个完成需要时间,延期的任务每天会有一个罚款, 现在所有任务都延期了,问最少的罚款是多少(每天只能做一种工作). 分析:贪心.转化问题为,如果不做则罚款的数额是days*Σ(每个任务罚款): 而每做好一个就认为从这一天开始以后每天都会获得相应的罚款的收益: 求收益的最大值即可,这里按性介比排序即可. 命题:按性介比排序受益最大. 证明:价值为p[i],耗时为c[i]则: 1.如果只有两个任务则有p[i]/c[i] > p[j]/c[j]  ->  p[i]

UVA 10026-Shoemaker’s problem(贪心)

Shoemaker's Problem Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ithjob, it is known the integer Ti (1<=Ti<=1000), the time in days it takes the shoemaker to finish the job

HDU 4974 A simple water problem(贪心)

HDU 4974 A simple water problem 题目链接 签到题,很容易贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100005; typedef long long ll; int t, n; ll a, Max, sum; int main(

Codeforces 442B Andrey and Problem(贪心)

题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,现在他有n个朋友,每个朋友想出题目的概率为pi,但是他可以同时向多个人寻求帮助,不过他只能要一道题,也就是如果他向两个人寻求帮助,如果两个人都成功出题,也是不可以的. 解题思路:贪心,从概率最大的人开始考虑,如果询问他使得概率变大,则要询问. #include <cstdio> #include <cstring> #include <a

programming-challenges Shoemaker&#39;s Problem (110405) 题解

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

an easy problem(贪心)

An Easy Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8333   Accepted: 4986 Description As we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form.

hdu----(5055)Bob and math problem(贪心)

Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 401    Accepted Submission(s): 149 Problem Description Recently, Bob has been thinking about a math problem.There are N Digit