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通过HttpProxy实现穿越

    需求描述     在正常的项目开发需求中,连接远程服务器的场景一般有二:     1  自家实现的http服务器,api接口都已经约定好:     2  开发平台服务,通常如新浪.百度云等平台提供的r ...

  2. [Eclipse] - 集成JBoss7热加载和自动发布

    使用Eclipse + JBoss开发时,总是要重启项目或JBoss,烦人.下面方法可以很简单的实现Eclipse + JBoss热加载和自动发布. 我的环境是JBoss 7.1.1 Final 1) ...

  3. 动态加载、移除、替换JS和CSS

    //动态加载一个js/css文件 function loadjscssfile(filename, filetype) { if (filetype == "js") { var ...

  4. Windows下用C++删除磁盘分区信息

    做一个能对U盘重新分区的小工具,使用该方法删除U盘中原有的分区表. bool CCesDiskDll::DestroyDisk(unsigned char deviceNumber) { DWORD ...

  5. 【dom4j】解析xml为map

    dom4j解析xml文件 <?xml version="1.0" encoding="utf-8"?> <workflows> < ...

  6. 数据库&数据仓库

    数据仓库的定义: 世界公认的数据仓库概念创始人W.H.Inmon在<数据仓库>(Building the Data Warehouse)一书中对数据仓库的定义是:数据仓库就是面向主题的.集 ...

  7. SQL%NOTFOUND

    异常相关: 源地址:https://zhidao.baidu.com/question/215737667.html EXCEPTIONwhen others thenrollback;dbms_ou ...

  8. Redis 新特性---pipeline(管道)

    转载自http://weipengfei.blog.51cto.com/1511707/1215042 Redis本身是一个cs模式的tcp server, client可以通过一个socket连续发 ...

  9. tmp_table_size

    Whenever you increase tmp_table_size and max_heap_table_size, keep in mind that setting these does n ...

  10. BMP图片格式

    BMP图片 BMP采用位映射存储格式,除了图像深度可选以外,不采用其他任何压缩,因此,BMP文件所占用的空间很大.BMP文件的图像深度可选lbit.4bit.8bit及24bit和32bit.BMP文 ...