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. SQL 数据库的使用

    <1>存到数据库 CSql Sql; Sql.SqlSave(15, &m_SALink, 0, 0, 0, 0); <2>取数据 int *pt = new int[ ...

  2. JS特殊函数(Function()构造函数、函数直接量)区别介绍

    函数定义 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 函数的构造语法有这三种: 1.function functionName(arg0, ...

  3. setsockopt 设置 SO_LINGER 选项

    setsockopt 设置 SO_LINGER 选项 最近和后台的server通信 server发现在读数据的时候  客户端已经关闭连接 ,也就是 没有等服务器读完数据,客户端已经fclose了, 联 ...

  4. 极值问题(acms)

    [问题描述] 已知m.n为整数,且满足下列两个条件: ① m.n∈{1,2,…,k},即1≤m,n≤k,(1≤k≤109). ②(n2-m*n-m2)2=1 你的任务是:编程输入正整数k,求一组满足上 ...

  5. Python 安装mysqldb

    切换目录: cd /usr/local/src/ 一.下载资源 wget http://sourceforge.net/projects/mysql-python/files/mysql-python ...

  6. [uboot]E9-i.MX6Q-uboot移植

      参照:http://blog.csdn.net/girlkoo/article/details/45420977 文档参照: <i.MX BSP Porting Guide-2015/12, ...

  7. python---hashlib

    简介 用于加密相关的操作,代替了md5模块和sha模块,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法. 在python3中已经废弃了md5和sha模块,简单说明 ...

  8. Tomcat长出现的内存溢出问题

    以下内容转载自博客:http://www.cnblogs.com/apaqi/archive/2012/07/09/2582480.html 在eclipse.ini配置文件中加上以下两行 -XX:P ...

  9. php 读取文件readfile

    <?php //读取文件 //echo readfile('aa.txt'); //打开文件更好的方法是fopen $f = fopen('aa.txt' , 'r') or die('unab ...

  10. .NET 环境中使用RabbitMQ(转)

    在企业应用系统领域,会面对不同系统之间的通信.集成与整合,尤其当面临异构系统时,这种分布式的调用与通信变得越发重要.其次,系统中一般会有很多对实时性要求不高的但是执行起来比较较耗时的地方,比如发送短信 ...