Day3-G - Task HDU4864
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.
InputThe 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.OutputFor 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 2
100 3
100 2
100 1
Sample Output
1 50004 思路:本题和H(Alice and Bob)一样,可看作偏序,x的权重大于y,将machine的x大于等于task的y值入队,每次入队最小的大于task的y值的,这样就能保证后面的y可以更多的匹配,
而x在入队时已经得到保证,代码如下:
typedef long long LL;
const int maxm = ;
struct Node {
int x, y;
bool operator<(const Node &a)const {
return x > a.x || (x == a.x && y > a.y);
}
} machine[maxm], task[maxm];
int n, t, tmp[];
int main() {
while(scanf("%d%d", &n, &t) == ) {
memset(tmp, , sizeof(tmp));
for (int i = ; i < n; ++i)
scanf("%d%d", &machine[i].x, &machine[i].y);
for(int i = ; i < t; ++i)
scanf("%d%d", &task[i].x, &task[i].y);
sort(machine, machine + n), sort(task, task + t);
int complete = ;
LL sum = ;
for(int i = , j = ; i < t; ++i) {
while(j < n && machine[j].x >= task[i].x) {
tmp[machine[j].y]++;
j++;
}
for (int k = task[i].y; k <= ; ++k) {
if(tmp[k]) {
++complete;
sum += task[i].x * * 1LL + * 1LL * task[i].y;
tmp[k]--;
break;
}
}
}
printf("%d %I64d\n", complete, sum);
}
return ;
}
补:
多者以上的贪心都要跟偏序挂钩
Day3-G - Task HDU4864的更多相关文章
- 牛客国庆集训派对Day3 G Stones
Stones 思路: sg函数打表找规律 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #in ...
- Multi-tasking RTOS for microprocessors with limited memory by saving only a single return address per task during context switching
A real-time operating system (RTOS) for use with minimal-memory controllers has a kernel for managin ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- WSL(Windows Subsystem for Linux)--Pico Process Overview
[转载] Windows Subsystem for Linux -- Pico Process Overview Overview This post discusses pico processe ...
- MTK6261 11C之Init Analysis【手记】
初始化流程 Application_Initialize systemInitialization(); HWDInitialization(); USC_Start(); OSTD_Init(); ...
- windows下使用vscode编写运行以及调试C/C++
未经允许,禁止转载,唯一出处:tangming博客园 最后更新于2019年4月4日: 多次更新,内容较多,篇幅较大,但如果是喜欢visual stdio code这款编辑器的话建议仔细阅读,有疑问的地 ...
- FuelPHP 系列(一) ------ Oil 命令
之前用过 Laravel,框架自带的 artisan 命令,用得爽到爆.现在工作需要,要学习 FuelPHP,首先看到框架目录结构,有 coposer.json 框架可以用 composer 管理,一 ...
- Should I expose synchronous wrappers for asynchronous methods?
In a previous post Should I expose asynchronous wrappers for synchronous methods?, I discussed " ...
- Should I expose asynchronous wrappers for synchronous methods?
Lately I've received several questions along the lines of the following, which I typically summarize ...
随机推荐
- 使用URLConnection获取页面返回的xml数据
public static void main(String[] args) throws Exception { String path="http://flash.weather.com ...
- PyQt5信号与槽详解
1.信号与槽函数基础'''信号与槽函数基础,信号是一个事件,发射信号之后槽函数就会执行'''from PyQt5.QtWidgets import *import sys class signal(Q ...
- 基于springboot通过注解AOP动态切换druid多数据源--mybatis
控制于接口之上: 开始:demo地址 在lsr-core-base中 自定义注解: /** * @Description: 数据源切换注解 * @Package: lsr-microservice ...
- 洛谷 T2691 桶哥的问题——送桶
嗯... 题目链接:https://www.luogu.org/problem/T2691 这道题有一点贪心的思想吧...并且思路与题目是倒着来的(貌似这种思路已经很常见的... 先举个栗子: 引出思 ...
- Suffix Tree(后缀树)
这篇简单的谈谈后缀树原理及实现. 如前缀树原理一般,后缀trie树是将字符串的每个后缀使用trie树的算法来构造.例如banana的所有后缀: 0: banana 1: anana 2: nana 3 ...
- video标签 在微信浏览器打开,不弹出大的独立窗口 而是直接播放。
1.在 video 标签中添加 属性 x5-playsinline playsinline webkit-playsinline="true" 2.ckplayer的 ...
- 什么是redis事务
一.什么是redis事务? 可以一次性执行多条命令,本质上是一组命令的集合.一个事务中的所有命令都会序列化,然后按顺序地串行化执行,而不会被插入其他命令 二.Redis 事务可以做什么? 一个队列中, ...
- java 依赖注入
https://blog.csdn.net/coderder/article/details/51897721 前言 在软件工程领域,依赖注入(Dependency Injection)是用于实现控制 ...
- 【转】IntelliJ IDEA 仿照vs2017快捷键设置,以及字体颜色设置
因后期工作需要使用java技术栈,所以近期抽空下载了intelliJ IDEA工具,但是作为一个Net开发者,在使用了vs以后,感觉在使用别的开发工具感觉就是没法和vs相比,毕竟vs被称为宇宙最强id ...
- 学习不一样的Vue1:环境搭建
学习不一样的Vue1:环境搭建 发表于 2017-05-31 | 分类于 web前端| | 阅读次数 11677 首先 首发博客: 我的博客 项目源码: 源码 项目预览: 预览 因为个人的喜好 ...