主题链接:

pid=4864">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
 
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(贪心)

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

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

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

  3. hdu 4864 Task

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

  4. HDU 4864 Task(经典贪心)

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

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

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

  6. hdu 4864 Task(贪心)

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

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

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

  8. hdu 4864 Task (贪心 技巧)

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

  9. HDU 4864 Task (贪心)

    Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/121336#problem/B Description Today the company has ...

随机推荐

  1. 【新秀疯狂UML系列】——面向对象的技术

    从软质工作开始,我们来到与面向对象的接触,接下来的学习材料似乎已经提到了面向对象,在与她的朋友去一个.所以,我们必须知道她多一点点. 一.何为面向对象? 面向对象(Object Oriented).是 ...

  2. MAC 10.10 apache 服务器配置

    mac中自带了apache服务器, 如果需要在mac上使用apache服务器, 只需要配置并启动服务器即可. mac 10.10 中自带的apache版本是 2.4 mac 10.9 中自带的apac ...

  3. php+sqlite cms

    1 phpSQLiteCMS 最新版本 phpSQLiteCMS 2.0.4 http://phpsqlitecms.net/ 2 taoCMS  最新版本 [2.5Beta5下载地址] 需要php ...

  4. linux shell中间$0,$?,$!和&lt;&lt;&#39;END&#39;

    变量说明: $$ Shell自己PID(ProcessID) $! Shell背景上次执行Process的PID $? 最后执行的命令结束码(回报值) $- 使用Set命令设定的Flag一览 $* 全 ...

  5. 父类中可继承方法在处理private的一个demo

    public abstract class AbstractParent { public AbstractParent() { System.out.println("Hello,pare ...

  6. 每天的学习经验:SharePoint 2013 定义自己添加的产品清单。Callout菜单项、文档关注、SharePoint服务机端对象模型查询

    前言: 前一段时间一直都比較忙.没有什么时间进行总结,刚好节前项目上线.同一时候趁着放假能够好好的对之前遇到的一些问题进行总结. 主要内容有使用SharePoint服务端对象模型进行查询.为Share ...

  7. hdoj1010Starship Troopers (树dp,依赖背包)

    称号:hdoj1010Starship Troopers 题意:有一个军队n个人要占据m个城市,每一个城市有cap的驻扎兵力和val的珠宝,并且这m个城市的占率先后具有依赖关系,军队的每一个人能够打败 ...

  8. js实现鼠标拖拽div-------Day44

    假设去问这样一个问题"你认为鼠标操作简单,还是键盘操作简单",相信会有多数人都会回答鼠标吧,毕竟键盘button那么多,假设手小了或者手法不规范了,太easy出问题了,也对操作的速 ...

  9. HttpWebRequest BeginGetResponse EndGetResponse

    private void Button_Click_4(object sender, RoutedEventArgs e) { HttpWebRequest request = HttpWebRequ ...

  10. 使用C#在Windows应用商店程序中获取CPU信息

    using Windows.Devices.Enumeration; string guidStr="{97FADB10-4E33-40AE-359C-8BEF029DBDD0}" ...