2014 Multi-University Training Contest 1/HDU4864_Task(贪心)
解题报告
题意,有n个机器。m个任务。
每一个机器至多能完毕一个任务。对于每一个机器,有一个最大执行时间Ti和等级Li,对于每一个任务,也有一个执行时间Tj和等级Lj。仅仅有当Ti>=Tj且Li>=Lj的时候,机器i才干完毕任务j,并获得500*Tj+2*Lj金钱。
问最多能完毕几个任务,当出现多种情况时,输出获得金钱最多的情况。
对任务和机器进行从大到小排序,从最大时间且最大等级的任务開始,选取全部符合时间限制的机器中等级要求最低的,这样能保证以下任务可选择的机器最多,如果选择的机器中等级要求最大的,接下去有一任务同样时间。却可能找不到可用的机器。
如机器(200,5)(200,2)任务(100,2)(99,4)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
#define LL __int64
using namespace std;
struct node
{
int t,l;
} ma[N],ta[N];
int n,m;
int cmp(node a,node b)
{
if(a.t==b.t)
return a.l>b.l;
else return a.t>b.t;
}
int main()
{
int i,j,k;
while(~scanf("%d%d",&n,&m))
{
LL sum=0;
int cnt=0;
for(i=0; i<n; i++)
scanf("%d%d",&ma[i].t,&ma[i].l);
for(i=0; i<m; i++)
scanf("%d%d",&ta[i].t,&ta[i].l);
sort(ma,ma+n,cmp);
sort(ta,ta+m,cmp);
int cc[110];
memset(cc,0,sizeof(cc));
for(i=0,j=0; i<m; i++)
{
while(j<n&&ta[i].t<=ma[j].t)
{
cc[ma[j].l]++;
j++;
}
for(k=ta[i].l; k<=100; k++)
{
if(cc[k])
{
sum+=(500*ta[i].t+2*ta[i].l);
cnt++;
cc[k]--;
break;
}
}
}
printf("%d %I64d\n",cnt,sum);
}
return 0;
}
Task
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1297 Accepted Submission(s): 321
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
2014 Multi-University Training Contest 1/HDU4864_Task(贪心)的更多相关文章
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2014 Multi-University Training Contest 9#11
2014 Multi-University Training Contest 9#11 Killing MonstersTime Limit: 2000/1000 MS (Java/Others) ...
- 2014 Multi-University Training Contest 9#6
2014 Multi-University Training Contest 9#6 Fast Matrix CalculationTime Limit: 2000/1000 MS (Java/Oth ...
- 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/法)
解题报告 两人轮流取球,大的人赢,,, 贴官方题解,,,反正我看不懂.,,先留着理解 关于费马小定理 关于原根 找规律找到的,,,sad,,, 非常easy找到循环节为p-1,每个循环节中有一个非零的 ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Ot ...
- hdu 4937 2014 Multi-University Training Contest 7 1003
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) T ...
- hdu 4941 2014 Multi-University Training Contest 7 1007
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
随机推荐
- Redis 起步(linux)
Rdis和JQuery一样是纯粹为应用而产生的,这里记录的是在CentOS 5.7上学习入门文章: 1.Redis简介 Redis是 一个key-value存储系统.和Memcached类似,但是解决 ...
- 基于 Node.js 的轻量「持续集成」工具 CIZE
CIZE 是什么? CIZE 是一个「持续集成」工具,希望能让开发人员更快捷的搭建一个完整.可靠.便捷的 CI 服务. 甚至可以像 Gulp 或 Grunt 一样,仅仅通过一个 cizefile.js ...
- OpenCV Harris 角点检测子
Harris 角点检测子 目标 本教程中我们将涉及: 有哪些特征?它们有什么用? 使用函数 cornerHarris 通过 Harris-Stephens方法检测角点. 理论 有哪些特征? 在计算机视 ...
- DICOM中的入门概念
DICOM标准是医学影像界技术人员逃不掉的标准.本系列专题是JATI对DICOM标准的阐述,力图使PACS管理员和软件工程师都能理解. DICOM标准的提出者DICOM标准委员会是ISO组织的合作者. ...
- c++ 读写Excel及数据导入SQLServer
c++ 读写Excel及数据导入SQLServer C++操作Excel ,网上的资料还是比较多的,写这篇文章也是分享给初学者一些经验. 本人 觉得CSpreadShe ...
- 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同
主要原因是: 两个文件行尾标题不一致而导致的,一个是PC,一个是Unix 解决办法: 随便比较文件夹中的两个文件,点击规则,去掉比较行尾(pc/mac/unix)选项,点击确认,回到文件夹比较界面,刷 ...
- (转)AS3 中,Function.apply、call中第一个参数的作用;与什么时候用
http://blog.csdn.net/linjf520/article/details/8746064 大家在使用Function.apply或是call时,是否发现,第一个参数不知道怎么用,赋值 ...
- windows 7 64bit安装apche php
http://windows.php.net/download#php-5.6-ts-VC11-x64http://www.apachehaus.com/cgi-bin/download.plx 下载 ...
- x为正变数,求y=x^3/(x^4+4)的最大值
设z=1/y=x4+4/x3 显然,当z有最小值时,y有最大值,求得zmin,就得到了ymax 而z=x+4/x3=x/3+x/3+x/3+4/x3 根据正实数算术平均数大于等于它们的几何平均数的定理 ...
- Oracle Spatial 创建空间表、添加空间原表信息、添加删除空间索引
一.创建空间表 创建一个空间表tbsvrc_buffer_t ,SQL如下: create table tbsvrc_buffer_t( ID VARCHAR2(50) not null, ...