Problem Description
In a factory, there are N workers to finish two types of tasks (A and B). Each type has N tasks. Each task of type A needs xi time to finish, and each task of type B needs yj time to finish, now, you, as the boss of the factory, need to make an assignment,
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.
 
Input
There are multiple test cases, in each test case there are 3 lines. First line there are two positive Integers, N (N<=1000) and T (T<=1000), indicating N workers, N task-A and N task-B, standard working hour T. Each of the next two lines has N positive Integers;
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).
 
Output
For each test case output the minimum Overtime wages by an integer in one line.
 
Sample Input
2 5
4 2
3 5
 
Sample Output
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 贪心法题解的更多相关文章

  1. 贪心法基础题目 HDU

    贪心算法的基本步骤: 1.从问题的某个初始解出发.2.采用循环语句,当可以向求解目标前进一步时,就根据局部最优策略,得到一个部分解,缩小问题的范围或规模.3.将所有部分解综合起来,得到问题的最终解. ...

  2. 杭电OJ1789、南阳OJ236(贪心法)解题报告

    杭电OJ1789http://acm.hdu.edu.cn/showproblem.php?pid=1789 南阳OJ236http://59.69.128.203/JudgeOnline/probl ...

  3. 《挑战程序设计竞赛》2.2 贪心法-区间 POJ2376 POJ1328 POJ3190

    POJ2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14585   Accepte ...

  4. NPC问题及其解决方法(回溯法、动态规划、贪心法、深度优先遍历)

    NP问题(Non-deterministic Polynomial ):多项式复杂程度的非确定性问题,这些问题无法根据公式直接地计算出来.比如,找大质数的问题(有没有一个公式,你一套公式,就可以一步步 ...

  5. 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262

    POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...

  6. 【ZROI 537】贪心题 题解

    [ZROI 537]贪心题 题解 Link Solution 最大的一边直接放到一起贪心即可 着重讲小的一边 已知对于二分图匹配,其答案即为最大流 令时间集合为 \(T = {1,2,3,\dots, ...

  7. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  8. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  9. 货币兑换问题(贪心法)——Python实现

      # 贪心算法求解货币兑换问题 # 货币系统有 n 种硬币,面值为 v1,v2,v3...vn,其中 v1=1,使用总值money与之兑换,求如何使硬币的数目最少,即 x1,x2,x3...xn 之 ...

随机推荐

  1. poj2418 map 快排水过

    /*计算每个单词的百分比按字典序输出*/ #include <cstdio>#include<cstdlib>#include <cstring>#include ...

  2. hdu4847 Wow! Such Doge!(简单题+坑爹的输入)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  3. POJ训练计划3041_Asteroids(二分图/最小点覆盖=最大匹配)

    解题报告 http://blog.csdn.net/juncoder/article/details/38135053 题目传送门 题意: 给出NxN的矩阵,有M个点是障碍 每次仅仅能删除一行或者一列 ...

  4. setOnClickListener报空指针异常

    1.异常提示: 2.错误原因: 先看代码: public class MainActivity extends ActionBarActivity { private Button btn_test; ...

  5. 配置QtCreator+CDB远程调试环境(要设置_NT_SYMBOL_PATH和QT_PLUGIN_PATH和Path)

    相关环境信息:开发机Win7 x64.远程机器WinXP.调试器是CDB.Qt版本5.2.1 一.部署远程机器环境 我这里用的是虚拟机(Windows XP),根据你要调试的程序选择安装不同架构的Wi ...

  6. error: /usr/include/stdio.h: Permission denied 的一种情况分析

    error: /usr/include/stdio.h: Permission denied 的一种情况分析 代码: #include <stdio.h> int main(){ prin ...

  7. go (break goto continue)

    package main import ( "fmt" ) func main() { LABEL1: for { ; i < ; i++ { { break LABEL1 ...

  8. SAE php 研究(2)

    1.在SAE新建项目打印出phpinfo <?php  print phpinfo(); ?> 2. 可见:PHP Version 5.3.8 [使用的是php5.3.8编译的] 3. 可 ...

  9. C语言盲点笔记1

    寥寥数笔,记录我的C语言盲点笔记,仅仅为以前经历过,亦有误,可交流. 1.int* a和int *a有差别吗? 没有不论什么差别,都表示a是int指针 建议这么写int *a;这样明显一点 理由例如以 ...

  10. 依据不同的操作系统读取配置文件/java读取属性文件代码

    package cn.com.css.common.util; /**  * @brief OSEnum.java 操作系统的枚举  * @attention  * @author 涂作权  * @d ...