主题链接:

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. 各种ESB产品比较(转)

    介绍了主流商业和开源ESB的发展趋势.可借鉴的地方和其缺点:         主要介绍:       Oracle Service Bus       WebSphere Message Broker ...

  2. FPGA 时序问题

    近期 做一个项目------4个 1080p(1920 x 1080) 合成 一个 4K(3840 x 2160,297M)的接口板.当 1080p 进去, 1080p出来的时候,视频正常 播放出来. ...

  3. oracle一视图性能问题

    oracle一些性能视图的解释  --关于是否收集 timed_statistics参数:用于决定是否收集相关的时间参数,true为收集.如果该参数设为false,则等待事件相关视图也就无法收集到数据 ...

  4. android:ViewPager动画摘要

    动画节目: 我们可以用ViewPager的setPageTransformer办法,至ViewPager动画.示及效果: 1.CubeInTransformer 2.CubeOutTransforme ...

  5. 基于最简单的FFmpeg的AVDevice抽样(屏幕录制)

    =====================================================基于最简单的FFmpeg的AVDevice样品文章: 最简单的基于FFmpeg的AVDevic ...

  6. Android4.0 Design之UI设计缺陷1

    我想成为Android卓越发展project联赛,不知道Android它如何设计规则,Android4.0谷歌公司的问世后Android一系列的设计原则,程序猿规范,不要盲目模仿IOS它的设计,由于A ...

  7. OCEANIAERP对接-code盘点机并存储实时库存计划和方案的使用,实时库存,云清查方案

    1.     PDA手持设备按键说明 [Tab]键:使输入焦点在控件上切换. [ESC]键:弹出是否退出确认对话框,退出操作界面或程序. [OK]键:确认输入或选择,进入下一步操作. [C]键:删除键 ...

  8. latex如何输入正确的 双引号

    latex当输入双引号,假设直接用双引号键在键盘上.玩过顺-handed. 引述左输入法是正确的:按两次"Tab在之上,数字1左边的键".至于后面行情,该方法是一样的老,这是两次单 ...

  9. OGG &quot;Loading data from file to Replicat&quot;table静态数据同步配置过程

    OGG "Loading data from file to Replicat"table静态数据同步配置过程 一个.mgr过程 GGSCI (lei1) 3> view p ...

  10. navicat如何导入sql文件

    工具--数据的传输--文件 版权声明:本文博客原创文章,博客,未经同意,不得转载.