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], ...
随机推荐
- NSOperation 的使用(下载相关) 图片和文件都是能够的 断点续传 图片逐渐显示
// // ImageDownloader.h // NSOperationTest // // Created by ydc on 11-10-29. // Copyright 2011年 __My ...
- 同一个存储过程中,不能多次select into 到同一张表的问题
表记录的插入方式有两种.其一,先create table 再 insert into from ....其二, 直接 select into. 第一种方式,由于要记录日志,因此IO消耗更多,durat ...
- oracle 关于日期格式转换与使用
在oracle中我们经常会和日期打交道,在做报表的时候经常会用日报,周报,月报之类的条件进行分组: 我写了些例子来启发下大脑 select Sysdate from dual select to_ch ...
- centos在设置时区
[root@localhost ~]# date -R // 查看时区 Mon, 19 May 2014 10:18:46 +0000 [root@localhost ~]# tzselect ...
- 2014在辛星Javascript口译科
***************概要*************** 1.Javascript是一种原型化继承的基于对象的动态类型的脚本语言,它区分大写和小写.主要执行在client,用户即使响应用户的操 ...
- [Windows Phone] 以多国语言做为开发前提 (1)
原文:[Windows Phone] 以多国语言做为开发前提 (1) ? 前言 在先前 TechDays 2013 的课程 [开发 Windows Phone 商务应用程式就是这麽快] 中,其中一个部 ...
- 理解和运用javascript中的call及apply
call是为了改变函数上下文context而存在的,换言之,就是改变函数内部this的指向.因为javascript存在[定义时上下文],[运行时上下文]及[上下文]是可以改变的.例如:var fun ...
- OpenCV——Delaunay三角 [转载]
从这个博客转载 http://blog.csdn.net/raby_gyl/article/details/17409717 请其它同学转载时注明原始文章的出处! Delaunay三角剖分是1934年 ...
- PHP制作pdf文档方法
原文:PHP制作pdf文档方法 本篇博客是在看完 php+mysql web书以后自己的测试代码,虽然是测试代码,但不是简单的粘贴复制,为了学习thinkPHP框架,自己就用这个来做的,而且这本书已经 ...
- 使用mysqlbinlog工具的基础上及时恢复数据的位置或点
使用mysqlbinlog工具的基础上及时恢复的位置或点 MySQL备份一般采取完全备份的形式加日志备份.让我们运行一个完整备份,每天.每小时运行二进制日志备份. 这样在MySQL Server故障后 ...