题目链接: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. uip UDPclient模式通信移植,p本地ort可以是无规

    现在移植UDPclient模式,使用广播地址检测. //udp_client.c /********************************************************** ...

  2. iOS 获取联系人,并调用系统地址簿UI

    1.加入 AddressBook库 推断授权状态 -(bool)checkAddressBookAuthorizationStatus { //取得授权状态 ABAuthorizationStatus ...

  3. sql server事物控制

    一.多个数据库 1.存储过程 2.Commit写在 Try...Catch后面 protected void Button1_Click(object sender, EventArgs e)    ...

  4. Swing程序最佳架构设计—以业务对象为中心的MVC模式(转)

    前言: 我打算写一系列关于Swing程序开发的文章.这是由于最近我在做一个Swing产品的开发.长期做JavaEE程序,让我有些麻木了.Swing是设计模式的典范,是一件优雅的艺术品,是一件超越时代的 ...

  5. 英特尔® 硬件加速执行管理器安装指南 — Microsoft Windows*

    介绍 本文将指导您安装英特尔® 硬件加速执行管理器(英特尔® HAXM),这是一款可以使用英特尔® 虚拟化技术(VT)加快 Android* 开发速度的硬件辅助虚拟化引擎(管理程序). 前提条件 英特 ...

  6. linux挂载U盘,及乱码问题解决

    1. 首先使用切换到root用户. 2. 使用fdisk -l命令查看磁盘信息,找到u盘(能够依据显示的大小确定) 3. 在/mnt下创建挂载点,比如创建usb目录:mkdir /mnt/usb 4. ...

  7. Eclipse——热键&amp;Help

    版权声明:本文博主原创文章.博客,未经同意不得转载.

  8. C#中的预编译指令介绍

    原文:C#中的预编译指令介绍 1.#define和#undef 用法: #define DEBUG #undef DEBUG #define告诉编译器,我定义了一个DEBUG的一个符号,他类似一个变量 ...

  9. [ACM] POJ 3686 The Windy&#39;s (二分图最小权匹配,KM算法,特殊建图)

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4158   Accepted: 1777 Descr ...

  10. LeetCode Solutions : Reorder List

    →-→Ln-1→Ln, reorder it to: L→Ln-2→- You must do this in-place without altering the nodes' values. Fo ...