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

题目:一家公司有m个任务需要完成,每件任务有一个最少工作时间和一个任务难度,同时这家公司一共有n台机器,每台对应一个最大工作时间和机器的等级,用这n台机器来完成任务。每台机器每天能完成一件任务----这件任务的需要的工作时间和任务难度分别要不超过机器的最长工作时间和机器的等级,每完成一件任务,公司获得500*任务工作时间+2*任务等级的利润。给定这些任务和机器的详细情况,问最多能完成多少件任务,利润是多少?(多种情况时输出最大利润)

题解的意思就是----每完成一件任务,获得利润=500*t+2*w,这里w的范围是1-100,最大值W=200<500对于整体利润的影响很小,所以对任务和时间均按照t递减排序,t相同按照w递减排序。然后从第一件任务开始遍历,找出所有能够解决这项任务的机器,并挑出工作时间最少,并且等级最低的那台来完成这项任务,以此类推,直到所有任务都完成。

为什么要这样安排呢?任务排序之后,后边的任务的一部分是时间与当前任务时间相同,但任务等级低的,能过解决当前任务的机器比人能够完成剩下的任务;另外一部分是时间比当前任务短,任务等级比当前任务高的,假设我挑走一台等级高机器,这台机器能完成这两项任务,另外存在一台机器等级低的机器只能完成当前任务,如果我用等级高的那台来完成当前任务的话,后来的任务就不能完成了,所以我要选择等级低但是能完成当前任务的那台机器;第三种情况,时间短,任务等级低的,能够完成当前任务的那些机器必然能用来完成这些任务。

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cmath>
  7. using namespace std;
  8. struct node
  9. {
  10. int x,y;
  11. }s1[100005],s2[100005];
  12. int cmp(node a,node b)
  13. {
  14. if(a.x == b.x)
  15. return a.y>b.y;
  16. return a.x>b.x;
  17. }
  18. int main()
  19. {
  20. int n,m,i,j,x,k;
  21. long long sum;
  22. while(~scanf("%d%d",&n,&m)){
  23. x = sum = 0;
  24. int c[101] = {0};
  25. for(i = 0; i<n; i++){
  26. scanf("%d%d",&s1[i].x,&s1[i].y);
  27. }
  28. for(i = 0; i<m; i++){
  29. scanf("%d%d",&s2[i].x,&s2[i].y);
  30. }
  31. sort(s1,s1+n,cmp);
  32. sort(s2,s2+m,cmp);
  33. for(i = 0,j = 0; i<m; i++){
  34. while(j<n && s1[j].x >= s2[i].x){ //将所有时间符合的都挑出来
  35. c[s1[j].y]++;
  36. j++;
  37. }
  38. for(k = s2[i].y; k <= 100; k++){ //从符合时间的里面挑出等级最低的一台来完成任务
  39. if(c[k]){
  40. c[k]--;
  41. sum += (s2[i].x*500+s2[i].y*2);
  42. x++;
  43. break;
  44. }
  45. }
  46. }
  47. cout<<x<<" "<<sum<<endl;
  48. }
  49. return 0;
  50. }

  

HDU4864:Task(贪心)的更多相关文章

  1. [HDU4864]Task (贪心)

    此图和上一篇博客的图一起看有奇效 题意 https://vjudge.net/problem/HDU-4864 思路 贪心 代码 by lyd 我实在是敲不来 #include <iostrea ...

  2. hdu4864 Task贪心好题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4864 题目大意: 有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间 ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. hdu4864 hdu4268 贪心 lower_bound

    hdu4864 题意: 有n个机器,m个任务,n,m<=100000,每个机器都有工作时间的最大限制xi(0<xi<1440)和完成的最大难度yi(0<=yi<=100) ...

  5. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  6. 2014多校第一场D题 || HDU 4864 Task (贪心)

    题目链接 题意 : 用N台机器,M个任务,每台机器都有一个最大工作时间和等级,每个任务有一个需要工作时间和一个等级.如果机器完成一个任务要求是:机器的工作时间要大于等于任务的时间,机器的等级要大于等于 ...

  7. HDU4864 Task(算竞进阶习题)

    贪心 比较巧妙的贪心..先把所有机器和任务按时间是第一关键字,等级为第二关键字排序. 然后用机器去匹配每一个任务. 排序之后,在时间上满足当前任务的机器,必定也在时间上满足后面的机器,所以我们每次把时 ...

  8. HDU 4864 Task(贪心)

    HDU 4864 Task 题目链接 题意:有一些机器和一些任务.都有时间和等级,机器能做任务的条件为时间等级都大于等于任务.而且一个任务仅仅能被一个机器做.如今求最大能完毕任务.而且保证金钱尽量多 ...

  9. HDU4864 Task

    题意 Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, t ...

随机推荐

  1. dl,dt,dd标签的使用

    dl就是定义一个列表 dt说明白了就是这个列表的标题dd就是内容,能缩进和UL,OL性质差不多 <dl> <dt>标题标题</dt> <dd>内容内容& ...

  2. java 11 值得关注的新特性

    JEP 181: Nest-Based Access Control 基于嵌套的访问控制 JEP 309: Dynamic Class-File Constants 动态类文件 JEP 315: Im ...

  3. 2017-12-19python全栈9期第四天第二节之列表的增删改查之切片

    #!/user/bin/python# -*- coding:utf-8 -*-li = ['zd',[1,3,4,5,6],'ls','ww','zl']l1 = li[0]print(l1)l2 ...

  4. Java小知识点总结

    目录 配置 数据库配置文件 基础知识 Switch i++和++i 快捷打代码 输入数据 代码折叠 super关键字 instanceof 防止类型强制转换带来的错误 继承 第一个Java程序 Jav ...

  5. mui扩展字体在哪里下载

    一次在一个知名前端模板网站上用积分下载了一个手机网页模板,没想到作者竟然玩起了删减隐藏,故意挖坑. 查看其原因是少一个mui.ttf的文件,纵然其他的文件及名称都有删改但无关紧要.也就是好多人搜索的m ...

  6. 学习WPF

    http://www.cnblogs.com/prism/archive/2010/07/21/1781855.html 如何在WPF中画三角,以及把按钮设置成颜色渐变的样式:

  7. js实现可输入的下拉框

    <HTML> <HEAD> <META http-equiv='Content-Type' content='text/html; charset=gb2312'> ...

  8. ccse(CountDownLatch,CycliBarrier,Semaplore,Exchanger)

    关于等待状态的线程调用interrupt方法报异常:InterruptedException 当线程被阻塞,比如wait,join,sleep等,在调用interrupt方法,没有占用cpu运行的线程 ...

  9. tensorflow 模型保存和加载

    使用 tf.train.Saver 保存:tf.train.Saver.save(sess, save_path, global_step=None, latest_filename=None, me ...

  10. json字符串CSS格式化

    其实JSON.stringify本身就可以将JSON格式化,具体的用法是: JSON.stringify(res, null, 2); //res是要JSON化的对象,2是spacing 如果想要效果 ...