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. 知识积累:CGI,FastCGI,PHP-CGI与PHP-FPM

    CGICGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.CGI可以用任何一种语 ...

  2. BigDecimal在实际项目的应用及遇到的问题

    我们都知道,java中对大小数,高精度的计算都会用到BigDecimal.但是在实际应用中,运用BigDecimal还是会遇到一些问题.下面说一下我在项目中怎么样BigDecimal和遇到的一些问题. ...

  3. springmvc权限过滤器

    package com.zbb.cn.filter; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; ...

  4. Google 的开源技术protobuf 简介与例子

    本文来自CSDN博客:http://blog.csdn.NET/program_think/archive/2009/05/31/4229773.aspx 今天来介绍一下"Protocol  ...

  5. Gson处理

    public class GsonTools { public GsonTools(){} public static <T> T getPerson(String jsonString, ...

  6. 黑马程序员_JAVA之银行业务调度系统

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 1.模拟实现银行业务调度系统逻辑,具体需求如下: 银行内有6个业务窗口,1 - 4号窗口为普通窗 ...

  7. (转载)RESTORE DATABASE命令还原SQLServer 2005 数据库

    今天恢复一个SQLServer2008R2,发现问题,然后通过园友的文章解决了问题,特记录备用 原文地址:http://www.cnblogs.com/adandelion/archive/2006/ ...

  8. VS2015 Android

    最近安装了VS2015,体验了一下android 的开发,按模板创建运行了个,试下效果很不错.也可以可视化设计.但昨天再次打开或创建一个android程序后,设计界面直接不能显示,显示错误:(可能是升 ...

  9. iOS开发官方文档汇总

    程序员的学习过程是无止境的,程序员学习的途径是多样的.可以从视频教程中领悟,也可以从他人的代码中 理解.但当我们专注于某一个平台在开发的时候,对于某个API使用或者功能实现有疑问,通常简单的测试可以让 ...

  10. Server 2003序列号

    windows2003 64位注册码 Windows 2003 R2 64bit Enterprise VOL Edition 企业版 MR78C-GF2CY-KC864-DTG74-VMT73 VP ...