HDU 1661 Assigments 贪心法题解
which makes sure that every worker could get two tasks, one in type A and one in type B, and, what's more, every worker should have task to work with and every task has to be assigned. However, you need to pay extra money to workers who work over the standard
working hours, according to the company's rule. The calculation method is described as follow: if someone’ working hour t is more than the standard working hour T, you should pay t-T to him. As a thrifty boss, you want know the minimum total of overtime pay.
the first line indicates the needed time for task A1, A2…An (Ai<=1000), and the second line is for B1, B2…Bn (Bi<=1000).
2 5
4 2
3 5
4
贪心思想:
1 先计算完毕任务A的每一个员工剩下多少时间
2 剩下时间越多的。就分配B任务时间越多
排序匹配。就非常好计算了。
#include <cstdio>
#include <algorithm>
using namespace std;
int A[1001];
int B[1001];
int main()
{
int N, T;
while (~scanf("%d %d", &N, &T))
{
for (int i = 0; i < N; i++)
{
scanf("%d", &A[i]);
A[i] = T - A[i];
}
for (int i = 0; i < N; i++)
{
scanf("%d", &B[i]);
}
sort(A, A+N);
sort(B, B+N);
int ans = 0;
for (int i = N-1; i >= 0; i--)
{
A[i] = B[i] - A[i];
if (A[i] > 0) ans += A[i];
}
printf("%d\n", ans);
}
return 0;
}
HDU 1661 Assigments 贪心法题解的更多相关文章
- 贪心法基础题目 HDU
贪心算法的基本步骤: 1.从问题的某个初始解出发.2.采用循环语句,当可以向求解目标前进一步时,就根据局部最优策略,得到一个部分解,缩小问题的范围或规模.3.将所有部分解综合起来,得到问题的最终解. ...
- 杭电OJ1789、南阳OJ236(贪心法)解题报告
杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...
- 《挑战程序设计竞赛》2.2 贪心法-区间 POJ2376 POJ1328 POJ3190
POJ2376 Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14585 Accepte ...
- NPC问题及其解决方法(回溯法、动态规划、贪心法、深度优先遍历)
NP问题(Non-deterministic Polynomial ):多项式复杂程度的非确定性问题,这些问题无法根据公式直接地计算出来.比如,找大质数的问题(有没有一个公式,你一套公式,就可以一步步 ...
- 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262
POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...
- 【ZROI 537】贪心题 题解
[ZROI 537]贪心题 题解 Link Solution 最大的一边直接放到一起贪心即可 着重讲小的一边 已知对于二分图匹配,其答案即为最大流 令时间集合为 \(T = {1,2,3,\dots, ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- 货币兑换问题(贪心法)——Python实现
# 贪心算法求解货币兑换问题 # 货币系统有 n 种硬币,面值为 v1,v2,v3...vn,其中 v1=1,使用总值money与之兑换,求如何使硬币的数目最少,即 x1,x2,x3...xn 之 ...
随机推荐
- 使用ANR-WatchDog来检測ANR
使用开源项目ANR-WatchDog来检測ANR.下载链接为:https://github.com/SalomonBrys/ANR-WatchDog Eclipse版本号仅仅需下载相应的jar包.在主 ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- 微软 自带 AJAX 拓展
<内容有点乱,自己找记忆的~~~> 微软自带AJAX 控件大全:控件简介: ScriptManager 控件 为启用了 AJAX 的 ASP.NET 网页管理客户端脚本. ScriptMa ...
- STL内存管理器的分配策略
STL提供了很多泛型容器,如vector,list和map.程序员在使用这些容器时只需关心何时往容器内塞对象,而不用关心如何管理内存,需要用多少内存,这些STL容器极大地方便了C++程序的编写.例如可 ...
- PropertyPlaceholderConfigurer类的使用注意
如果你在spring的applicationcontext.xml中需要使用属性配置文件,那PropertyPlaceholderConfigurer这个类就是必须的. <bean class= ...
- hibernate级联保存问题,出错not-null property references a null or transient value
Servlet.service() for servlet default threw exception org.hibernate.PropertyValueException: not-null ...
- Mybatis在oracle、mysql、db2、sql server的like模糊查询
<!-- oracle --> <select id="searchUserBySearchName" parameterType="java.lang ...
- 公司内网Debian Server上的openvpnserver搭建并通过SSH隧道转发到广域网
因为戴维营公司在长沙的学员,研发人员和北京的研发人员须要协同研发,故须要让北京的兄弟们增加到长沙办公室的内网,訪问版本号 管理server,于是採用在内网server上搭建一个OpenVPN服务,并把 ...
- Latin1的所有字符编码
ISO-8859-1 (ISO Latin 1) Character Encoding Contents The characters at a glance Character codes and ...
- 温故知新-------jQuery层次选择器
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></titl ...