HDU4864:Task(贪心)

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

题意:n台机器,m个任务,每台机器和任务都有两个值,机器的两个值都大于任务的两个值,这台机器才干完毕这个任务,每台机器仅仅能完毕一个任务,问最大收益

思路:贪心,标记好暴力就可以

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct node
{
    int x,y;
} s1[100005],s2[100005];

int cmp(node a,node b)
{
    if(a.x == b.x)
        return a.y>b.y;
    return a.x>b.x;
}

int main()
{
    int n,m,i,j,cnt;
    __int64 sum;
    while(~scanf("%d%d",&n,&m))
    {
        for(i = 0; i<n; i++)
            scanf("%d%d",&s1[i].x,&s1[i].y);
        for(i = 0; i<m; i++)
            scanf("%d%d",&s2[i].x,&s2[i].y);
        sort(s1,s1+n,cmp);
        sort(s2,s2+m,cmp);
        cnt = sum = 0;
        int c[105] = {0};
        for(i = 0,j = 0; i<m; i++)
        {
            while(j<n && s1[j].x>=s2[i].x)
            {
                c[s1[j].y]++;
                j++;
            }
            for(int k = s2[i].y; k<=100; k++)
            {
                if(c[k])
                {
                    c[k]--;
                    sum+=(s2[i].x*500+s2[i].y*2);
                    cnt++;
                    break;
                }
            }
        }
        printf("%d %I64d\n",cnt,sum);
    }
}
时间: 2024-08-29 12:46:21

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

[HDU4864]Task (贪心)

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

hdu 4869 Task(贪心)

题目链接:hdu 4869 Task 题目大意:有n台机器,m个任务,每个机器和任务都有有xi和yi,要求机器的xi,yi均大于等于任务的xi和yi才能执行任务.每台机器一天只能执行一个任务.要求完成的任务数尽量多,并且说金额尽量大.完成每个任务的金额为xi?500+yi?2 解题思路:贪心,mach[i][j]表示等级为i,时间为j的机器数量,task[i][j]表示等级为i,时间为j的机器数量.每次优先减少i,因为对应等级减少100,对应的金额代价也不会减少超过500(即时间减少1). 每次

HDU 4864 Task(贪心)

HDU 4864 Task 题目链接 题意:有一些机器和一些任务,都有时间和等级,机器能做任务的条件为时间等级都大于等于任务,并且一个任务只能被一个机器做,现在求最大能完成任务,并且保证金钱尽量多 思路:贪心,对于每个任务,时间大的优先去匹配,时间相同的,等级大的优先去匹配,因为时间占得多,时间多1就多500,而等级最多才差200.然后匹配的时候,尽量使用等级小的去匹配,而时间只要大于它的都可以用,因为是按时间优先,所以如果该时间能匹配大的,其他肯定也能匹配,那么肯定优先匹配大的,所以只要在等级

Codeforces 583 DIV2 Robot&#39;s Task 贪心

原题链接:http://codeforces.com/problemset/problem/583/B 题意: 就..要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使得总花费最小. 题解: 就傻傻的走就好..从左走到右,再走回来,更新序列和答案就好. 代码: #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define MA

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

题目链接 题意 : 用N台机器,M个任务,每台机器都有一个最大工作时间和等级,每个任务有一个需要工作时间和一个等级.如果机器完成一个任务要求是:机器的工作时间要大于等于任务的时间,机器的等级要大于等于任务的等级.一台机器只能完成一个任务,一个任务只能被一台机器完成.每个机器完成一个任务公司能够获得500*xi+2*yi (此处xy都是指被完成的任务的).输出所有机器能完成的最多任务数,和最大盈利. 思路 :贪心,自己做的时候想了各种排序都不对,没有考虑到500*xi+2*yi 这个公式的重要性.

HDU_4864 Task 贪心

今天多校的一道题,哎,多校被中学生碾压了 发现自己很怕敲贪心,这道题其实贪心特性相当明显,我看这个题算比较早,还在想各种递推或者dp那种 后来还是聪哥马上反应过来了 首先,对于任何的task,因为最后的money是 500*x+2*y,所以,在得到最多money方面,肯定是x的优先级高,x相同的时候再比较y 然后题目是要求 在保证最多任务完成量的前提下,money最多,在任务完成量方面,首先,题目一个很明显的说法是一个机器只能跟一个task对应,所以,一个task如果只是占用了刚好够自己用的机器

HDU4864(Task)

题目地址:Task 题目大意: n台机器,m个任务,每台机器和任务都有两个值,机器的两个值都大于任务的两个值,这台机器才能完成这个任务,每台机器只能完成一个任务,问最大收益. 解题思路: 因为尽量处理时间大的任务,所以机器和任务先按时间从大到小排序,尽量找与task相接近的时间和等级,先将机器时间大于task1的所有机器按照机器的等级存入一个数组,然后按照task1的等级找最接近的处理机器,因为必须先处理时间高的任务,因为它需要乘500,一定很大,之所以找task1的等级找最接近,这样以保证后面

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可以工作的最长时间和一个可以完成的任务的难度的最大值, 一台机器能完成一个任务的条件是这台机器的最长工作时间和能完成任务的难度值必须都大于等于这个任务,而且一台机器最多完成一个任务,假设一个任务的时间为t,难度值为x,那么完成这个任务可以赚到的钱 money = 500 * t + 2 * x; 现在

hdu 4864 Task (贪心 技巧)

题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi>=xj且yi>=yj的时候,机器i才能完成任务j,并获得 500*xj+2*yj金钱.问最多能完成几个任务,当出现多种情况时,输出获得金钱最多的情况. 分析:机器和任务都按照先拍x从大到小,再拍y从大到小的顺序.然后遍历任务,注意f[]数组的作用,f[]数组标 记大于当前任务时间的机器的等级个数,