传送门:

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): 11382    Accepted Submission(s): 2782

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
 
题目意思:
 
给你N个机器和M个任务, 每个任务有两个值花费时间x和难度y,
 
每个机器也有两个值最大工作时间x1和最大工作难度y1, 机器可以胜任某个工作的条件是x1>=x && y1>=y,
 
机器胜任一个工作可以拿到x*500+2*y的钱,现在问你怎么匹配才能使匹配数最大且钱数最多。
 
分析:
问你怎么匹配钱数最多
肯定是贪心的思想:
将任务按照权值1降序排序,权值1相同的按照权值二降序排序
将机器也同样是如此
在给任务选择机器的时候,在满足要求的机器中(机器的两个权值都大于任务的两个权值)选择权值1最给小的分配给该任务,这样保证了后面任务做的可能性增大
为什么是选择机器权值1最小的分配而不是权值2最小的呢?
因为权值1是乘以100,权值2是乘以1
肯定选择权值1嘛
 
code:
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <cstdlib>
#include <queue>
#include<string.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define max_v 100005
typedef long long LL;
struct node
{
int x,y;
}p1[max_v],p2[max_v];
int cmp(node a,node b)
{
if(a.x==b.x)
{
return a.y>b.y;
}else
{
return a.x>b.x;
}
}
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=;i<n;i++)
cin>>p1[i].x>>p1[i].y;
for(int i=;i<m;i++)
cin>>p2[i].x>>p2[i].y;
sort(p1,p1+n,cmp);
sort(p2,p2+m,cmp);
int cnt=;
LL sum=;
int c[]={};
for(int i=,j=;i<m;i++)
{
while(j<n&&p1[j].x>=p2[i].x)
{
c[p1[j].y]++;
j++;
}
for(int k=p2[i].y;k<=;k++)
{
if(c[k])
{
c[k]--;
sum+=(p2[i].x*+p2[i].y*);
cnt++;
break;
}
}
}
printf("%d %I64d\n",cnt,sum);
}
return ;
}
 

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

  1. hdu 4864 Task(贪心)

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

  2. HDU 4864 Task (贪心)

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

  3. HDU 4864 Task(贪心)

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

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

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

  5. hdu 4864 Task

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

  6. hdu 4864 Task(贪婪啊)

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

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

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

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

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

  9. hdu 4864 Task (贪心 技巧)

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

随机推荐

  1. python模块之contexlib

    一.上下文管理器 with是python实现上下文管理器的核心关键词.它能够在代码执行前和执行后做一些额外的事情. 最常见的代码恐怕就是文件操作了. with open("file" ...

  2. 1、springboot之HelloWorld

    最基本的,官网copy 创建maven项目 maven中添加 <parent> <groupId>org.springframework.boot</groupId> ...

  3. C Primer Plus note2

    warning: 'mmin' is used uninitialized in this function [-Wuninitialized]| 编译器出现如上图的警告,是因为变量‘mmin’没有初 ...

  4. Windows下etc文件夹

    etc etcetera[ɛtsɛtərə]缩写 等等的意思 放置一些其他文件

  5. 一道google的面试题(据说)

    1. 原题(同事给的) Max Howell 参加了谷歌的面试,出题人竟然要求 Max Howell 在白板上作出解答,Max Howell 当然愤怒地拒绝了,回家以后马上在微博上跟我们分享他的吐槽: ...

  6. The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)

    1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...

  7. html+css 布局篇

    float 做了float后有一些不好的影响. 1.背景不能显示 由于浮动产生,如果对父级设置了(CSS background背景)CSS背景颜色或CSS背景图片,而父级不能被撑开,所以导致CSS背景 ...

  8. Apache Phoenix on CDH 5

    We are happy to announce the inclusion of Apache Phoenix in Cloudera Labs. [Update: A new package fo ...

  9. 07_dubbo_compiler

    [开始解析最后一行代码 ExtensionLoader.getAdaptiveExtension()] ExtensionLoader<Protocol> loader = Extensi ...

  10. as3.2版本中中jar生成方法

    lintOptions { abortOnError false } task makeJar(type: Copy) { //删除存在的 delete 'build/libs/myjar.jar' ...