题目链接: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): 1035    Accepted Submission(s): 245

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 4869 4868 4867 4866 
 

这是一道贪心的题,要求任务数最多,并且钱也要最多。

那么我们首先先对任务排序,先按时间排序,若时间一样,则依照level排。

之后呢,我们依次选择时间和level最接近该任务的就可以。

因为这道题数据范围比較大,在tle了n次之后,所以我參考了某神牛的博客,採用了set和二分查找进行优化,时间复杂度瞬间就降下来了。。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
const int MAX=100005;
struct Task{
int x,y;
}t[MAX];
bool cmp(Task a,Task b){if(a.x==b.x) return a.y>b.y;else return a.x>b.x;};
inline ll f(int x,int y){return 500*x+2*y;}
int main(){
int n,m;
while(cin>>n>>m){
multiset<int> st[105];
int maxlevel=0,cnt=0;
ll sum=0;
for(int i=0;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
st[y].insert(x);
maxlevel=max(maxlevel,y);
}
for(int i=0;i<m;i++){scanf("%d%d",&t[i].x,&t[i].y);}
sort(t,t+m,cmp);
for(int i=0;i<m;i++){
int u=t[i].x,v=t[i].y;
for(int j=v;j<=maxlevel;j++){
if(st[j].empty()) continue;
multiset<int>::iterator it=st[j].lower_bound(u);
if(it==st[j].end()||*it<u) continue;
else{
cnt++;sum+=f(u,v);
st[j].erase(it);
break;
}
}
}
cout<<cnt<<" "<<sum<<endl;
}
return 0;
}

hdu 4864 Task---2014 Multi-University Training Contest 1的更多相关文章

  1. HDU 4864 Task(贪心)

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

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

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

  3. hdu 4864 Task(贪婪啊)

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

  4. HDU 4864 Task(经典贪心)

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

  5. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  6. hdu 4864 Task

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

  7. HDU 6143 - Killer Names | 2017 Multi-University Training Contest 8

    /* HDU 6143 - Killer Names [ DP ] | 2017 Multi-University Training Contest 8 题意: m个字母组成两个长为n的序列,两序列中 ...

  8. HDU 6074 - Phone Call | 2017 Multi-University Training Contest 4

    看标程的代码这么短,看我的.... 难道是静态LCA模板太长了? /* HDU 6074 - Phone Call [ LCA,并查集 ] | 2017 Multi-University Traini ...

  9. HDU 6068 - Classic Quotation | 2017 Multi-University Training Contest 4

    /* HDU 6068 - Classic Quotation [ KMP,DP ] | 2017 Multi-University Training Contest 4 题意: 给出两个字符串 S[ ...

  10. HDU 6076 - Security Check | 2017 Multi-University Training Contest 4

    /* HDU 6076 - Security Check [ DP,二分 ] | 2017 Multi-University Training Contest 4 题意: 给出两个检票序列 A[N], ...

随机推荐

  1. MySql模糊查询like通配符简介

    %代表随意多个字符  _代表一个字符 在 MySQL中.SQL的模式缺省是忽略大写和小写的 正则模式使用REGEXP和NOT REGEXP操作符. "."匹配不论什么单个的字符.一 ...

  2. tokumx经营报表

    #见数据库列表  show dbs #切换/创建数据库(当创建一个集合(table)的时候会自己主动创建当前数据库) use admin; #添加用户  db.addUser("zhoulf ...

  3. Java中动态代理技术生成的类与原始类的区别

    用动态代理的时候,对它新生成的类长什么样子感到好奇.有幸通过一些资料消除了心里的疑惑. 平时工作使用的Spring框架里面有一个AOP(面向切面)的机制,只知道它是把类重新生成了一遍,在切面上加上了后 ...

  4. SessionA和pplication网上聊天室的网络范例

    login.aspx码,如以下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...

  5. t持久化与集群部署开发详解

    Quartz.net持久化与集群部署开发详解 序言 我前边有几篇文章有介绍过quartz的基本使用语法与类库.但是他的执行计划都是被写在本地的xml文件中.无法做集群部署,我让它看起来脆弱不堪,那是我 ...

  6. POJ 2152 Fire

    算是我的第一个树形DP 的题: 题目意思:N个城市形成树状结构.现在建立一些消防站在某些城市:每个城市有两个树形cost(在这个城市建立消防站的花费),limit : 我们要是每个城镇都是安全的:就是 ...

  7. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第7章节--打包并部署SP2013 Apps 打包并公布App

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第7章节--打包并部署SP2013 Apps 打包并公布App         如今既然你理解了一个app的四个主要部分, ...

  8. 【Web探索之旅】第二部分第五课:响应式网站和移动应用

    内容简介 1.第二部分第五课:响应式网站和移动应用 2.第三部分第一课预告:服务器 第二部分第五课:响应式网站和移动应用 在我们开始聊响应式网站之前,我们可以聊聊移动App(App是Applicati ...

  9. Team Foundation Server 2013 Update 3 下载激活

    http://www.microsoft.com/zh-cn/download/details.aspx?id=43728 支持的操作系统 Windows 7 Service Pack 1, Wind ...

  10. 无法使用Django新建项目:&#39;django-admin.py&#39;不是内部或外部命令

    问题: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbXlhdGxhbnRpcw==/font/5a6L5L2T/fontsize/400/fill/I0 ...