题意

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 (500xi+2yi) 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.

1 < =N <= 100000,1<=M<=100000
0<xi<1440, 0=<yi<=100

分析

参照knownothing的题解。

将任务已x从大到小排序(x相同时已y从大到小排序)。然后也用相同排序方法排序机器。开始遍历任务,找出所有xi(xi>=xj),从中选择yi最小的一个作为这个任务的运行机器。为什么这么贪心,因为若还存在任务(xk,yk)使得这个机器能被使用,但xj>=xk,所以获得金钱更多,优先选择j;若k不能使用这个机器,那么必定也就不存在其他机器能被使用,除非是新加入的机器,但新加入的必定不能完成任务j,所以完成任务保证了最多。

使用了归并写法,时间复杂度\(O(My_i+N)\)。

代码

#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
    rg T data=0,w=1;
    rg char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
        data=data*10+ch-'0',ch=getchar();
    return data*w;
}
template<class T>il T read(rg T&x){
    return x=read<T>();
}
typedef long long ll;
using namespace std;

co int N=1e5;
struct node{
    int x,y;
    bool operator<(co node&a)co{
        return x^a.x?x>a.x:y>a.y;
    }
}e[N],f[N];
int c[101];
int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<n;++i)
            read(e[i].x),read(e[i].y);
        for(int i=0;i<m;++i)
            read(f[i].x),read(f[i].y);
        sort(e,e+n);
        sort(f,f+m);
        memset(c,0,sizeof c);
        int num=0;
        ll ans=0;
        for(int i=0,j=0;i<m;++i){
            while(j<n&&e[j].x>=f[i].x)
                ++c[e[j].y],++j;
            for(int k=f[i].y;k<=100;++k) if(c[k]){
                ++num,--c[k];
                ans+=500*f[i].x+2*f[i].y;
                break;
            }
        }
        printf("%d %lld\n",num,ans);
    }
    return 0;
}

HDU4864 Task的更多相关文章

  1. [HDU4864]Task (贪心)

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

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

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

  3. hdu4864 Task贪心好题

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

  4. POJ1723,1050,HDU4864题解(贪心)

    POJ1723 Soldiers 思维题. 考虑y坐标,简单的货舱选址问题,选择中位数即可. 再考虑x坐标,由于直接研究布置方法非常困难,可以倒着想:不管如何移动,最后的坐标总是相邻的,且根据贪心的思 ...

  5. HDU4864:Task(贪心)

    Problem DescriptionToday the company has m tasks to complete. The ith task need xi minutes to comple ...

  6. Day3-G - Task HDU4864

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

  7. HDU4864:Task(贪心)

    题意: 给出n个机器和m个任务,对于一天来说,每个机器有最大工作时间xi,可接受最大等级yi,每个任务有一个工作时间xi,一个等级yi,可获价值为500*xi+2*yi,任务需要在一台机器一天内完成, ...

  8. hdu4864 hdu4268 贪心 lower_bound

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

  9. Concepts:Request 和 Task

    当SQL Server Engine 接收到Session发出的Request时,SQL Server OS将Request和Task绑定,并为Task分配一个Workder.在TSQL Query执 ...

随机推荐

  1. MySQL安装的N种方式

    一.二进制包安装 1.)下载:在官网的下载页面下的服务器操作系统选择  Linux- Generic : 进制分发版的格式是:mysql-<版本>-<OS>-tar.gz 2. ...

  2. linux bash shell中,单引号、 双引号,反引号(``)的区别及各种括号的区别

    一.单引号和双引号 首先,单引号和双引号,都是为了解决中间有空格的问题. 因为空格在Linux中时作为一个很典型的分隔符,比如string1=this is astring,这样执行就会报错.为了避免 ...

  3. 前端开发必备 - Emmet

    介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具. 基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为"片段".虽然片 ...

  4. Mit-Scheme 安装小记

    Win10 到 http://www.gnu.org/software/mit-scheme/ 下载对应平台的安装包,我下载的是windows 版本 安装到本地后只出现一个快捷方式MIT-GNU Sc ...

  5. 通过fork进程爆破canary

    1.1.1    通过fork进程爆破canary ⑴.原理分析: 对fork而言,作用相当于自我复制,每一次复制出来的程序,内存布局都是一样的,当然canary值也一样.那我们就可以逐位爆破,如果程 ...

  6. jqeury 基础

    jquery 选择器: 基本选择器:#id ..class.*(匹配所有) 层次选择器: $(div span) 选取<div>里的所有的<span>元素. $(div> ...

  7. LINUX中文件描述符传递

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  8. is7.0中发布mvc网站,一直无法正常执行路由的解决办法

    在config中加一句话: <system.webServer> <validation validateIntegratedModeConfiguration="fals ...

  9. Linux:split命令详解

    split 可以将一个大文件分割成很多个小文件,有时需要将文件分割成更小的片段,比如为提高可读性,生成日志 语法 split(选项)(file)PREFIX 选项 -b:值为每一输出档案的大小,单位为 ...

  10. 《Drools7.0.0.Final规则引擎教程》第4章 4.4 LHS简介&Pattern

    LHS简介 在规则文件组成章节,我们已经了解了LHS的基本使用说明.LHS是规则条件部分的统称,由0个或多个条件元素组成.前面我们已经提到,如果没有条件元素那么默认就是true. 没有条件元素,官方示 ...