Assignments

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1463    Accepted Submission(s): 675

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
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3665 3667 3664 3669 3668 
 

题意:给出n个工人,n个a类耗时和b类耗时,要求每个工人搭配一个a类的和b类的,每个工人、每个耗时都要有被分配。超出T的按超出的算。求超出最少的搭配。

贪心头加尾。不过总觉得有问题。

 //203MS    236K    648 B    C++
#include<stdio.h>
#include<stdlib.h>
#define N 1005
int a[N];
int b[N];
int cmp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
inline int max(int a,int b)
{
return a>b?a:b;
}
int main(void)
{
int n,t;
while(scanf("%d%d",&n,&t)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int j=;j<n;j++)
scanf("%d",&b[j]);
qsort(a,n,sizeof(a[]),cmp);
qsort(b,n,sizeof(b[]),cmp);
int vis[N]={};
int ans=;
for(int i=;i<n;i++)
ans+=max(,a[i]+b[n-i-]-t);
printf("%d\n",ans);
}
return ;
}

hdu 3661 Assignments (贪心)的更多相关文章

  1. HDU 3661 Assignments (水题,贪心)

    题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...

  2. hdu 3661 Assignments(水题的解法)

    题目 //最早看了有点云里雾里,看了解析才知道可以很简单的排序过 #include<stdio.h> #include<string.h> #include<algori ...

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

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

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

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

  5. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  6. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  7. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  9. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

随机推荐

  1. 黑马程序员——JAVA基础之File类,递归,打印流,合并切割流

    ------- android培训.java培训.期待与您交流! ---------- File类 用来将文件或者文件夹封装成对象 方便对文件与文件夹的属性信息进行操作. File对象可以作为参数传递 ...

  2. 20151216Repeater

    Repeater 用法:.绑定数据源 Repeater1.DataSource = context.Info; Repeater1.DataBind(); .造项模版: 头模版:HeaderTempl ...

  3. mac osx 制作安装u盘

    制作OS X El Capitan 原版安装U盘:sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/creat ...

  4. JQuery AJAX 解析获得的JSON数据

    下面的解析的Json是一个二级循环. <!DOCTYPE html> <html> <head> <script src="https://code ...

  5. eclipse美化

    // */ // ]]>   eclipse美化 Table of Contents 1 中文字体 2 皮肤 3 emacs+ 1 中文字体 win7下打开eclipse3.7中文字体很小,简直 ...

  6. Spring 中的default-lazy-init="true" 和 lazy-init="true"

    1.spring的default-lazy-init参数 spring在启动的时候,会默认加载会默认加载整个对象实例图,从初始化ACTION配置.到 service配置到dao配置.乃至到数据库连接. ...

  7. jQuery使用示例详解

    [jquery引用字段] <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv ...

  8. [家里蹲大学数学杂志]第047期18 世纪法国数学界的3L

    1 Lagrange---78岁 约瑟夫·拉格朗日, 全名约瑟夫·路易斯·拉格朗日 (Joseph-Louis Lagrange 1735~1813) 法国数学家.物理学家. 1736年1月25日生于 ...

  9. Xamarin.Froms项目中包含的文件

    Clearly, the program created by the Xamarin.Forms template is very simple, so this is an excellent o ...

  10. MYSQL C API : struct MYSQL_STMT 结构的组合使用

    #include <iostream> #include <string> #include <string.h> #include <assert.h> ...