主题链接:

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. Hibernate HQL详细说明

    1.  Hibernate HQL详细说明 1.1.  hql一个简短的引论 Hibernate它配备了一种非常强大的查询语言.这种语言看起来非常像SQL.但是不要 要对相位的语法结构似,HQL是很有 ...

  2. 【C语言探索之旅】 第二课:工欲善其事,必先利其器

    内容简介 1.课程大纲 2.第一部分第二课:工欲善其事,必先利其器 3.第一部分第三课预告:你的第一个程序 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C ...

  3. 开源Math.NET基础数学类库使用(09)相关数论函数使用

    原文:[原创]开源Math.NET基础数学类库使用(09)相关数论函数使用               本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4 ...

  4. C#启动进程之Process

    在程序设计中,我们经常会遇到要从当前的程序跳到另一个程序的设计需求.也就是当前进程创建另一个进程.C#提供了Process使得我们很方便的实现. 1.Process基本属性和方法 Id //进程的Id ...

  5. 腾讯2014在广州站实习生offer经验(TEG-开发背景)

    研究在过去的一年是linux 什么系统编程和网络编程.比较熟悉的语言c/c++,python只写一些测试client.是后台开发类,比方前面笔面的网易CC(面完hr后挂).大概3月15号就在腾讯 jo ...

  6. Objective-C路成魔【2-Objective-C 规划】

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 编译执行O ...

  7. Android 儿子Activity在启动过程中的流程组件 &amp;&amp; 儿子Activity在一个新的进程组件启动过程

    1.儿子Activity在启动过程中的流程组件 在Android Activity启动过程http://blog.csdn.net/jltxgcy/article/details/35984557一文 ...

  8. iOS kvc

    kvc在我的脑海里用来更改属性的实例变量值. 今天,他们遇到了kvc第二次去学习它,在网上看了很多博客,这似乎不符合我的口味,为了提取一些以下的.总结自己的. http://www.cnblogs.c ...

  9. yii组态 redis主从配置(随着代码)

    最近的欲望redis 主从,但yii内建的redis 它不支持主从.不仅写了一个好办法 结构例,以下: 1.main.php通过添加下面的句子: //redis缓存配置 'cache_redis' = ...

  10. Android采用canvas绘制各种图形

    canvas通俗的说就是一个帆布,我们可以用刷子paint,就此随机抽签显卡. 原理: 能够canvas视Surface替代或接口.图形绘制Surface向上.Canvas封装了全部的绘制调用. 通过 ...