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 ...
随机推荐
- 实验3 OpenGL几何变换
转自:http://www.cnblogs.com/opengl/archive/2012/10/30/2747130.html 1.实验目的: 理解掌握一个OpenGL程序平移.旋转.缩放变换的方法 ...
- 使用OllyDbg破解软件
好,废话不多说,教程开始. 我们首先查壳,是Aspark的壳,对于这个壳,大家应该很熟了.<ignore_js_op> 我已经脱好了壳,再查一下壳,是Dephi的<ignore ...
- Eclipse启动项目时,删除workspaces无用的工作区间
选择菜单栏的window-->Preferences-->General-->Startup and Shutdown-->workspaces, Recent workspa ...
- MERGE新特性(UPDATE WHERE,DELETE WHERE,INSERT WHERE)
MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句.通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询,连接条件匹配上的进行UPDATE,无法匹配的执 ...
- HttpClient使用例子
HttpClient client = new HttpClient(); String url = http://localhost:8080/ana/workFlowOaInterface.do? ...
- 代码规范审查 - Sonar集成Visual Studio
开发人员可以使用Sonar的集成插件在开发阶段进行实时代码质量审核,在代码编写阶段分析出当前代码的质量及规范漏洞,并给出合理的修改建议.编写高质量.高维护性的代码变得更简单! VS集成Sonar之前 ...
- Spring3.0.5jar包用法详解 [转载]
Spring3.X以后jar包进行了重构,取消了原来2.X版本中的总的spring.jar包,而是把总包中的功能全部分开打包.正在向osgi靠拢. 各个jar包详解如下: 1. org.springf ...
- 在Spark程序中使用压缩
当大片连续区域进行数据存储并且存储区域中数据重复性高的状况下,数据适合进行压缩.数组或者对象序列化后的数据块可以考虑压缩.所以序列化后的数据可以压缩,使数据紧缩,减少空间开销. 1. Spark对压缩 ...
- sqlmap使用帮助文档(1)
当给sqlmap这么一个url的时候,它会: 1.判断可注入的参数 2.判断可以用那种SQL注入技术来注入 3.识别出哪种数据库 4.根据用户选择,读取哪些数据 sqlmap支持五种不同的注入模式: ...
- 黑马程序员:多线程Socket
---------------------- ASP.Net+Android+IOS开发..Net培训.期待与您交流! ----------------------- 一.Socket一般应用模式(服 ...