Task

题目链接:

http://acm.hust.edu.cn/vjudge/contest/121336#problem/B

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 (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.

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个任务,每台机器有对应的工作时间和难度上限,每个任务有时间需求和难度.
每个任务的报酬由时间和难度决定(500*x+2*y).
求最多完成多少任务,任务数相同时报酬尽量多.


##题解:

一开始看题目以为是每个任务有时间\难度\金钱三个因素,不方便进行贪心操作.
仔细观察题目数据范围和所给的公式后发现:时间x增加1报酬会增加500,而难度最多增加100会提升报酬200;
所以时间才是决定报酬的要素,按照时间降序排列(时间相等时难度降序)后,任务的报酬也就有序了.

现在的问题是对于每个任务,如何选取完成这个任务的机器:
由于我们对机器和任务都排序过,那么时间上能满足当前任务的机器一定也能够满足接下来任务.

而对于若干个时间上满足当前任务的机器,应该选择难度上限尽量小(但满足当前任务)的机器; 而留下难度上限大的机器以待完成后面的需求.

算法流程:
先对机器和任务都按照上述规则排序:
依次扫描每个任务,先找到时间上满足任务要求的全部机器,并将它们的难度上限在数组中标记出来(因为难度的范围只有100,记录每个难度有多少机器能应对即可). 最后找出最小能满足任务难度要求的机器即可.
WA点:难度是从0开始的; 报酬总数要用longlong


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 101000
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;

int n, m;

typedef pair<int,int> pii;

pii machine[maxn];

pii task[maxn];

int lev_cnt[110];

int main(int argc, char const *argv[])

{

//IN;

while(scanf("%d %d", &n,&m) != EOF)
{
memset(lev_cnt, 0, sizeof(lev_cnt));
for(int i=1; i<=n; i++) {
int x,y; scanf("%d %d", &x,&y);
machine[i] = make_pair(x,y);
}
for(int i=1; i<=m; i++) {
int x,y; scanf("%d %d", &x,&y);
task[i] = make_pair(x,y);
}
sort(machine+1, machine+1+n, greater<pii>());
sort(task+1, task+1+m, greater<pii>()); int finish = 0;
LL money = 0;
for(int i=1,j=1; i<=m; i++) {
int t = task[i].first;
int lev = task[i].second;
for(; j<=n; j++) {
if(machine[j].first >= t)
lev_cnt[machine[j].second]++;
else break;
} for(int k=0; k<=100; k++) {
if(!lev_cnt[k]) continue;
if(k >= lev) {
lev_cnt[k]--;
finish++;
money += 500LL*(LL)t + 2LL*(LL)lev;
break;
}
}
} printf("%d %I64d\n", finish, money);
} return 0;

}

HDU 4864 Task (贪心)的更多相关文章

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

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

  2. HDU 4864 Task(贪心)

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

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

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

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

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

  5. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

  6. HDU 4864 Task(经典贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others)    M ...

  7. hdu 4864 Task

    题目链接:hdu 4864 其实就是个贪心,只是当初我想的有偏差,贪心的思路不对,应该是这样子的: 因为 xi 的权值更重,所以优先按照 x 来排序,而这样的排序方式决定了在满足任务(即 xi > ...

  8. hdu 4864 Task(贪婪啊)

    主题链接:pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS ...

  9. hdu 4864 Task(贪心)

    pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864 大致题意:有n台机器和m个任务,都有两个參数工作时间time和难度le ...

随机推荐

  1. IOS代码

    //// MJViewController.m// UITableView-编辑模式//// Created by mj on 13-4-11.// Copyright (c) 2013年 itcas ...

  2. 创建支持复杂脚本Complex Scripts的WINCE6.0系统

    如果要创建支持复杂脚本(Complex Scripts)的系统,我们需要完成下面一系列步骤来确保系统包含所有需要支持的具体区域设置 (locale–specific). 1.     选择intern ...

  3. C++ STL之查找算法

    C++STL有好几种查找算法,但是他们的用法上有很多共同的地方: 1.除了binary_search的返回值是bool之外(查找的了返回true,否则返回false),其他所有的查找算法返回值都是一个 ...

  4. gulp 使用mailgun服务器发送邮件

    1.首先你需要创建一个 mailgun 账户,没有请去注册一个. 注册之后会有 mailgun 会给你一个默认的子域名,你就可以使用这个子域名去发送邮件了,如下图: 2.gulp创建任务: var s ...

  5. Jenkins iOS – Git, xcodebuild, TestFlight

    Introduction with Jenkins iOS If you are new to continuous integration for mobile platforms then you ...

  6. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  7. LA 4636 (贪心) Cubist Artwok

    题意: 一个由若干小正方体组成的图形,给出它的正视图和侧视图,求满足条件的最少小正方体的个数. 分析: 虽说是一道简单的贪心,可一直没有太好的思路. 又一次可耻地看了别人的题解. http://blo ...

  8. JS创建Ajax的XMLHttpRequest对象的通用方法

    function createXMLHttpRequest() { var request = false; if(window.XMLHttpRequest) { request = new XML ...

  9. Codeforces Round #272 (Div. 2)

    A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2 ...

  10. eclipse启动出现“An Error has Occurred. See the log file”解决方法

    最近在启动eclipse时出现了“An Error has Occurred. See the log file”的错误,点击确定后也不能启动eclipse.查看log文件,出现类似: java.la ...