[贪心&&排序]UVA10670 Work Reduction

Problem C: Work Reduction

Paperwork is beginning to pile up on your desk, and tensions at the workplace are starting to mount. Your boss has threatened to fire you if you don't make any progress by the end of the day. You currently have  N  units of paperwork on your desk, and your boss demands that you have exactly  M  units of paperwork left by the end of the day.

The only hope for you now is to hire help. There are various agencies which offer paperwork reduction plans:

For $A they will reduce your paperwork by one unit.
For $B they will reduce your entire paperwork by half (rounding down when necessary).

Note that work can never be reduced to less than 0.

Your task now is to produce a sorted table of agency names and their respective minimum costs to solve your workload problem.

The first line of input consists of a single positive integer representing the number of cases to follow. Each case begins with three positive integers separated by spaces: N - your starting workload, M - your target workload, and L - the number of work reduction agencies available to you, (1 <= M <= N <= 100000, 1 <= L <= 100). The next L lines have the format "[agency name]:A,B", whereA and B are the rates as described above for the given agency. (0 <= A,B <= 10000) The length of the agency name will be between 1 and 16, and will consist only of capital letters. Agency names will be unique.

For each test case, print "Case X", with X being the case number, on a single line, followed by the table of agency names and their respective minimum costs, sorted in non-decreasing order of minimum costs. Sort job agencies with identical minimum costs in alphabetical order by agency name. For each line of the table, print out the agency name, followed by a space, followed by the minimum required cost for that agency to solve your problem.

Sample Input

2
100 5 3
A:1,10
B:2,5
C:3,1
1123 1122 5
B:50,300
A:1,1000
C:10,10
D:1,50
E:0,0

Sample Output

Case 1
C 7
B 22
A 37
Case 2
E 0
A 1
D 1
C 10
B 50

Gilbert Lee

题意:现在有N个任务要做,而且要留M个到明天做,你自己做不完,只能请团队帮你做,每个团队有两种方案,一个一个任务做或者把你当前的任务的一半做掉,花费各不相同,求出对每一个团队的最小花费。

思路:典型的贪心题目,每次都选择最优方案,并且保证当前的任务数量大于等于M。

代码:

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

class Node
{
public:
	string str;
	int cost;
}node[10005];

bool cmp(Node s1,Node s2)
{
	if(s1.cost!=s2.cost) return s1.cost<s2.cost;
	else return s1.str<s2.str;
}

int main()
{
	int num,pos;
	cin>>num;
	for(pos=1;pos<=num;pos++)
		{
			int x,y,z,r,t;
			cin>>x>>y>>z;
			char ch;
			for(int i=0;i<z;i++)
				{
					int work=x;
					string st="";
					while(cin>>ch&&ch!=':')
						{
							st=st+ch;
						}
					node[i].str=st;
					cin>>r>>ch>>t;
					int val=0;
					while(t<((work+1)/2*r)&&(work-(work+1)/2)>=y)
						{
							val=val+t;
							work=work-(work+1)/2;
						}
					val=val+(work-y)*r;
					node[i].cost=val;
				}
			sort(node,node+z,cmp);
			cout<<"Case "<<pos<<endl;
			for(int i=0;i<z;i++)
				{
					cout<<node[i].str<<" "<<node[i].cost<<endl;
				}
		}
	return 0;
}



利用 TensorFlow 训练自己的目标识别器。本文内容来自于我的毕业设计,基于 TensorFlow 1.15.0,其他 TensorFlow 版本运行可能存在问题。.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值