hdu 4864 Task---2014 Multi-University Training Contest 1
题目链接: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
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.
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.
1 2
100 3
100 2
100 1
1 50004
这是一道贪心的题,要求任务数最多,并且钱也要最多。
那么我们首先先对任务排序,先按时间排序,若时间一样,则依照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的更多相关文章
- HDU 4864 Task(贪心)
HDU 4864 Task 题目链接 题意:有一些机器和一些任务.都有时间和等级,机器能做任务的条件为时间等级都大于等于任务.而且一个任务仅仅能被一个机器做.如今求最大能完毕任务.而且保证金钱尽量多 ...
- Hdu 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- hdu 4864 Task(贪婪啊)
主题链接:pid=4864">http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS ...
- HDU 4864 Task(经典贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=4864 Task Time Limit: 4000/2000 MS (Java/Others) M ...
- 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 ...
- hdu 4864 Task
题目链接:hdu 4864 其实就是个贪心,只是当初我想的有偏差,贪心的思路不对,应该是这样子的: 因为 xi 的权值更重,所以优先按照 x 来排序,而这样的排序方式决定了在满足任务(即 xi > ...
- HDU 6143 - Killer Names | 2017 Multi-University Training Contest 8
/* HDU 6143 - Killer Names [ DP ] | 2017 Multi-University Training Contest 8 题意: m个字母组成两个长为n的序列,两序列中 ...
- HDU 6074 - Phone Call | 2017 Multi-University Training Contest 4
看标程的代码这么短,看我的.... 难道是静态LCA模板太长了? /* HDU 6074 - Phone Call [ LCA,并查集 ] | 2017 Multi-University Traini ...
- HDU 6068 - Classic Quotation | 2017 Multi-University Training Contest 4
/* HDU 6068 - Classic Quotation [ KMP,DP ] | 2017 Multi-University Training Contest 4 题意: 给出两个字符串 S[ ...
- HDU 6076 - Security Check | 2017 Multi-University Training Contest 4
/* HDU 6076 - Security Check [ DP,二分 ] | 2017 Multi-University Training Contest 4 题意: 给出两个检票序列 A[N], ...
随机推荐
- adodb.RecordSet的属性和方法
为了更精确地跟踪数据,要用RecordSet组件创建包括数据的游标,游标就是储存在内存中的数据: rs = Server.CreateObject("ADODB.RecordSet" ...
- current online redo logfile 丢失的处理方法
昨天做了rm -rf操作后的恢复演练,并且是在没有不论什么备份的情况下.今天在做破坏性操作前,做了个rman全备,然后在线删除所有数据库文件,包含控制文件,数据文件,在线日志文件,归档文件等.来看看有 ...
- 趣味Java算法题(附答案)
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每一个月都生一对兔子,小兔子长到第三个月后每一个月又生一对兔子,假如兔子都不死,问每一个月的兔子总数为多少? //这是一个菲波拉契 ...
- JavaScript获取路径
JavaScript获取路径 1.设计源代码 <%@ page language="java" import="java.util.*" pageEnco ...
- 在mac os下编译android -相关文章
1. Mac OS X下编译Android源码 http://blog.csdn.net/bulreed/article/details/22783467 2.MAC OS 编译 Android源代码 ...
- Linux下常用操作汇总
查看linux操作系统位数 (1) 终端输入: file /sbin/init 如 显示: /sbin/init: ELF 32-bit LSB executable, Intel 80386, ve ...
- Linux学习笔记——举例说,makefile 多个文件
0.前言 从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力. 所以特意 ...
- QEMU-KVM自己主动创建虚拟机,以指定IP构造
正在使用qemu不能指定创建虚拟机的过程IP住址,然而,在实际应用中,我们需要有一台虚拟机IP住址,不是人为的虚拟机操作系统配置. 于qemu虚拟机技术文档(http://qemu.weilnetz. ...
- PHPthinking官方论坛
PHPthinking官方论坛正式上线一个月!眼下.我们已经有数百个固定用户的.论坛发展迅速,所有份额一些技术贴,我们希望,其他许多用户增加来,创建学习.交流更方便.丰富的内容PHP座谈会! PHPt ...
- C#中禁止程序多开
原文:C#中禁止程序多开 方法一.使用Mutex bool createdNew; //返回是否赋予了使用线程的互斥体初始所属权 System.Threading.Mutex i ...