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. mysql特殊处理

    mysql> create table ef (bc time);Query OK, 0 rows affected (0.03 sec) mysql> insert into ef va ...

  2. FineUI中Newtonsoft.Json版本报错解决办法

    1.清空bin下的Newtonsoft.Json.dll 2.使用Nuget安装最新版本的Newtonsoft.Json.dll,安装脚本为 Install-Package Newtonsoft.Js ...

  3. c++读写二进制文件

    要读取文件必须包含<fstream>头文件,这里包含了C++读写文件的方法,可以使用fstream 类,这个类可以对文件进行读写操作.   1.打开文件.   打开文件可以有两种方式,第一 ...

  4. Openstack Neutron DVR workflow

    目前在Juno版本的trunk中已经合入了DVR相关的代码,我的理解是在Juno版本中DVR是一个experimental feature.最好需要稳定一个版本以后再上生产环境.之前写过一篇博文是DV ...

  5. C#:org.in2bits.MyXls 文本格式日期 转换,以及设置单元格格式,保留两位小数点

    org.in2bits.MyXls  Excel导入日期格式的处理 表格内容为 2014-7-22 ,导入后显示为 41842 等于一个数值,根本不是日期,后来百度了一下,发现要做如下处理: stri ...

  6. ROC曲线

    1.混淆矩阵(confusion matrix)     针对预测值和真实值之间的关系,我们可以将样本分为四个部分,分别是:     真正例(True Positive,TP):预测值和真实值都为1 ...

  7. php利用zookeeper作dispatcher服务器

    ===== https://blog.eood.cn/php_share_memory 最常见的apc 可以缓存php的opcode提高应用的性能,可以在同个php-fpm进程池间共享数据 常见功能: ...

  8. Java事务处理全解析(八)——分布式事务入门例子(Spring+JTA+Atomikos+Hibernate+JMS)

    在本系列先前的文章中,我们主要讲解了JDBC对本地事务的处理,本篇文章将讲到一个分布式事务的例子. 请通过以下方式下载github源代码: git clone https://github.com/d ...

  9. JVM垃圾回收参数说明整理

    java -Xms4g -Xmx4g -Xmn3g -Xss256k -server -XX:PermSize=64M -XX:MaxPermSize=64M -XX:+UseConcMarkSwee ...

  10. android studio This client is too old to work with the working copy at

    http://www.cnblogs.com/maijin/archive/2013/01/09/2852330.html http://stackoverflow.com/questions/283 ...