主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864

Task

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1346    Accepted Submission(s): 336
Problem Description
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.
Input
The input contains several test cases.
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.
Output
For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.
Sample Input
1 2 100 3 100 2 100 1
Sample Output
1 50004
Author
FZU
Source
2014 Multi-University Training Contest 1
Recommend
We have carefully selected several similar problems for you:  4871 4870 4869 4868 4867 

基本思想是贪心:

对于价值c=500*xi+2*yi,yi最大影响100*2<500,所以就是求xi总和最大。

能够先对机器和任务的时间从大到小排序。从最大时间的任务開始。找出满足任务时间要求的全部机器。从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100017;
struct work
{int x,y;
}ma[N],ta[N];
bool cmp(work a, work b)
{if(a.x == b.x)return a.y > b.y;return a.x > b.x;
}
int main()
{int n, m;int i, j;int c[N];while(~scanf("%d%d",&n,&m)){memset(c,0,sizeof(c));for(i = 1; i <= n; i++){scanf("%d%d",&ma[i].x,&ma[i].y);}for(i = 1; i <= m; i++){scanf("%d%d",&ta[i].x,&ta[i].y);}sort(ma+1,ma+n+1,cmp);sort(ta+1,ta+m+1,cmp);int l = 1;__int64 ans = 0;int num = 0;for(i = 1; i <= m; i++){while(l <= n&&ma[l].x >= ta[i].x){//寻找全部的能完毕当前任务的机器c[ma[l].y]++;l++;}for(j = ta[i].y; j <= 100; j++){//寻找全部能完毕当前任务的机器中等级最低的if(c[j]){num++;ans+=500*ta[i].x+2*ta[i].y;c[j]--;break;}}}printf("%d %I64d\n",num,ans);}return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

hdu 4864 Task(贪婪啊)相关推荐

  1. HDU 4864 Task(2014多校--贪心)

    Task 比赛当时思路想的差不多,感觉能过的,该处理的也都处理到了,最后还是没过,可能是二分写错了吧-.- 大意:给你n个机器,m个要完成的任务,每个机器跟任务都有两个属性,机器是最大工作时间跟等级, ...

  2. HDU 4864 Task(贪心或高斯消元)

    题意:n台机器工作时间为ai,等级bi,m个任务需要时间ai,等级bi,一台机器只能完成一个任务,完成一个任务收益为500*ai+2*bi,求最大收益:(n,m>100000) 思路:先从大到小 ...

  3. hdu 3572 Task Schedule 网络流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...

  4. hdu 4864(2) 线段树

    对task和machine的yi由小到大进行排序,然后对machine来跟task配对.当machine[].yi >= task[].yi时,就更新线段树,在1-1440上做线段树,线段树存的 ...

  5. HDU 3572 Task Schedule

    传送门 作业调度,这道题还真没想到能用网络流....乍一看跟背包问题差不多. 有N个作业,M个机器,每个作业给你一个耗费时间(时间段)以及最早开始时间和最晚完成时间(这两个是时间点),单位是天.一个作 ...

  6. hdu 3572 Task Schedule IPSA 最大流

    题意: 题目意思: 给出 N 件任务和 M台机器, 这N件任务都一个限制: 必须在 [S,E] 之间完成, 而且完成的时间不能超过 P. 一台机器每天只能做意见任务, 不过庆幸的是: 任务是可以拆分的 ...

  7. 题解报告:hdu 4907 Task schedule

    Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务. 有m个询问,每个询问有一个数字q,表示如果在q时 ...

  8. hdu4864 Task

    原题: http://acm.hdu.edu.cn/showproblem.php?pid=4864 大神解题报告: http://www.cnblogs.com/xingxing1024/p/527 ...

  9. WaWa的奇妙冒险(第四周集训自闭现场)

    第四周周记(退火大法好,玄学保平安) (一)wlacm例题记录 A-FBI树 (水题,位运算) Input Output Sample Input Sample Output 理解 AC代码 B-查找 ...

最新文章

  1. 压缩感知(III) A Compressed Sense of Compressive Sensing (III)
  2. Pycharm 创建 Django admin 用户名和密码
  3. int、unsigned int、float、double 和 char 在内存中存储方式
  4. c语言数值运算法和非数值运算法,数据结构(c语言)1.数据结构是一门研究非数值计算的程序设计问题中计算机的 以及它们之间的 _ 和运算等的学科。① A....
  5. cleanmymac 4.2_市委刚刚批准:11月1号立即执行! 农业银行存款利率4.2%,1万元存1年,有多少利息?...
  6. 《流畅的Python》读书笔记——Python使用一等函数实现设计模式
  7. 雨棚板弹性法计算简图_旌阳移动推拉雨棚移动蓬定制
  8. pandas之Dataframe 菜鸟教程
  9. rtl驱动 ubuntu 禁用_【Ubuntu】UEFI安装Windows 10和Ubuntu 18.04双系统(深度爬坑)
  10. zmap扫描mysql_互联网扫描器 ZMap 完全手册
  11. 欧姆龙PLC数据读写工具。 支持FinsTCP实测好用打开欧姆龙PLC读写软件,输入IP地址和端口号
  12. IIC总线设计③——光敏传感器(BH1750)
  13. Ubuntu下bazel卸载与安装
  14. RK3588 RGA 图像操作
  15. Java 面试题大全(整理版)1000+ 面试题附答案详解
  16. 可以查询天气的日历——QT制作第一个自己的小软件
  17. linux 怎么改系统字体,Linux如何更改字体
  18. 黑白琴键 java_在黑白琴键的世界里,学钢琴的意义是什么?
  19. 线上线下效果一致性杂谈
  20. 关于小公司产品开发的几点建议

热门文章

  1. 2008wsus创建和管理计算机组,Windows Server 2012 R2 WSUS-6:配置计算机组和客户端目标...
  2. java工程怎么构造成moven_将普通java工程结构改为由maven管理的工程结构域
  3. 处理入参_看看优秀的程序员是如何处理NPE的
  4. gcc编译器java_「gcc编译器下载」gcc编译器下载各版本下载 - seo实验室
  5. php document.getel,javascript 密码强弱度检测万能插件_javascript技巧
  6. 能用来写安卓吗_iPad能代替笔记本吗,除了看剧还能用来做什么?
  7. cx oracle dpi 1002,cx_Oracle连接数据库总结
  8. android设置输入框输入字符限制,Android EditText限制输入字符的方法总结
  9. python父亲节祝福_父亲节祝福语精选简短 父亲节祝福语简短独特
  10. Uvaoj 11624 - Fire!