2014 Multi-University Training Contest 1/HDU4864_Task(贪心)
来源:互联网 发布:打蛇电影 知乎 编辑:程序博客网 时间:2024/06/09 04:47
解题报告
题意,有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 __int64using 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
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.
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.
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 2100 3100 2100 1
Sample Output
1 50004
Author
FZU
Source
2014 Multi-University Training Contest 1
0 0
- 2014 Multi-University Training Contest 1/HDU4864_Task(贪心)
- 2014 Multi-University Training Contest 1小记
- 2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1 题解
- 2014 Multi-University Training Contest 1
- 2017 Multi-University Training Contest 1 1002. Balala Power!(贪心)
- 2014 Multi-University Training Contest 1 D(hdu 4864 经典贪心)
- 2014 Multi-University Training Contest 1--by FZU 解题报告
- 2014 Multi-University Training Contest 1/HDU4861_Couple doubi(数论/规律)
- hdu4864 Task 2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 1 - A. Couple doubi
- hdu 4861 Couple doubi ---2014 Multi-University Training Contest 1
- 关于2014 Multi-University Training Contest 1的反思
- 2014 Multi-University Training Contest 1 — D. Task
- 2014 Multi-University Training Contest 1--by FZU 解题报告
- windows 配置IPython
- 网页设计多伦多 - 最有效的工具
- 网络分析是至高无上的方式来了解你的网站和网站流量
- js下拉加载分页
- linux内存管理介绍
- 2014 Multi-University Training Contest 1/HDU4864_Task(贪心)
- Play Framework 关于cronExpression的介绍 ,定时任务
- android 移动开发 实现上拉加载更多实现方式
- 声音断续、卡顿问题分析
- java产生全球唯一ID——GUID(UUID)
- 保护您的公司有监控软件
- 深入理解HashMap
- 使用适当的工具确定社交媒体分析的价值
- Android Ant 多渠道打包