hdu 4864 Task(贪婪啊)

主题链接: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): 1346    Accepted Submission(s): 336


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.
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.
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 2 100 3 100 2 100 1
Sample Output
1 50004

Author
FZU
Source
2014 Multi-University Training Contest 1
Recommend
We have carefully selected several similar problems for you:  4871 4870 4869 4868 4867 

基本思想是贪心

对于价值c=500*xi+2*yiyi最大影响100*2<500,所以就是求xi总和最大。

能够先对机器和任务的时间从大到小排序。从最大时间的任务開始。找出满足任务时间要求的全部机器。从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100017;
struct work
{int x,y;
}ma[N],ta[N];
bool cmp(work a, work b)
{if(a.x == b.x)return a.y > b.y;return a.x > b.x;
}
int main()
{int n, m;int i, j;int c[N];while(~scanf("%d%d",&n,&m)){memset(c,0,sizeof(c));for(i = 1; i <= n; i++){scanf("%d%d",&ma[i].x,&ma[i].y);}for(i = 1; i <= m; i++){scanf("%d%d",&ta[i].x,&ta[i].y);}sort(ma+1,ma+n+1,cmp);sort(ta+1,ta+m+1,cmp);int l = 1;__int64 ans = 0;int num = 0;for(i = 1; i <= m; i++){while(l <= n&&ma[l].x >= ta[i].x){//寻找全部的能完毕当前任务的机器c[ma[l].y]++;l++;}for(j = ta[i].y; j <= 100; j++){//寻找全部能完毕当前任务的机器中等级最低的if(c[j]){num++;ans+=500*ta[i].x+2*ta[i].y;c[j]--;break;}}}printf("%d %I64d\n",num,ans);}return 0;
}


版权声明:本文博主原创文章。博客,未经同意不得转载。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544144.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

svg学习网站

1、http://www.runoob.com/svg

EasyExcel太方便易用了,强烈推荐!

背景 系统中经常要导出大量的数据&#xff0c;格式基本上都是Excel&#xff0c;然而每次导表都是对系统内存的一次挑战。在Java领域&#xff0c;生成或解析Excel的框架比较有名的当属Apache的poi和jxl了。但使用它们&#xff0c;会面临着严重的内存损耗问题。如果系统的并发量还…

Java Date hashCode()方法与示例

日期类hashCode()方法 (Date Class hashCode() method) hashCode() method is available in java.util package. hashCode()方法在java.util包中可用。 hashCode() method is used to retrieve hash code of this Date object. hashCode()方法用于检索此Date对象的哈希码。 has…

eclispe快捷键

快捷键无效解决办法&#xff1a; 1、考虑是否被其他应用占用&#xff0c;如QQ&#xff0c;QQ音乐&#xff0c;千千动听等 2、在eclispe查看是否被修改&#xff1a;Window->Preferences->General->Keys 快捷键&#xff1a; 1、复制当前行到下一行&#xff1a;CtrlAlt↓…

【端午】送3本书!

白天在公司搬砖&#xff0c;晚上到家赶紧给小伙伴们安排一波福利&#xff0c;这次送的书是 H 大新出的《深入理解Java核心技术&#xff1a;写给Java工程师的干货笔记&#xff08;基础篇&#xff09;》。书中介绍了普通Java工程师必须要学习的相关知识点&#xff0c;包括面向对象…

java bitset_Java BitSet length()方法与示例

java bitsetBitSet类的length()方法 (BitSet Class length() method) length() method is available in java.util package. length()方法在java.util包中可用。 length() method is used to return the length of this BitSet otherwise it returns 0 when this BitSet is &qu…

SpriteBuilder物理对象的父子关系

注意:打开物理使能(Physics-enabled)的节点忽略他们的父节点关系. 这意味着,一个物理使能的子节点不会随着其父节点移动. 物理引擎对于节点父子关系这个概念毫不知情,因此单独的对待所有物理使能的节点,意味着这些节点与其他节点相互独立. 我强烈建议你在设计所有复杂物理对象的…

面试突击51:为什么单例一定要加 volatile?

.作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;单例模式的实现方法有很多种&#xff0c;如饿汉模式、懒汉模式、静态内部类和枚举等&#xff0c;当面试官问到“为什…

kotlin 扩展类的功能_Kotlin程序| 扩展功能功能

kotlin 扩展类的功能扩展功能 (Extension function) Kotlin provides the ability to add more functionality to the existing class without inheriting them. Kotlin可以在不继承现有类的情况下为其添加更多功能。 This is done via a special declaration called "Ext…

聊聊保证线程安全的10个小技巧

前言对于从事后端开发的同学来说&#xff0c;线程安全问题是我们每天都需要考虑的问题。线程安全问题通俗的讲&#xff1a;主要是在多线程的环境下&#xff0c;不同线程同时读和写公共资源&#xff08;临界资源&#xff09;&#xff0c;导致的数据异常问题。比如&#xff1a;变…

Raid控制器

转载于:https://blog.51cto.com/xuepengdou/1699799

并行计算机架构_计算机科学组织| 并行处理

并行计算机架构并行处理 (Parallel Processing) Parallel processing is processing of the data concurrently. We process the data concurrently to fulfill the demands of the increasingly high performance so that to achieve better throughput instead of processing…

15个必知的Mysql索引失效场景,别再踩坑了!

背景 无论你是技术大佬&#xff0c;还是刚入行的小白&#xff0c;时不时都会踩到Mysql数据库不走索引的坑。常见的现象就是&#xff1a;明明在字段上添加了索引&#xff0c;但却并未生效。前些天就遇到一个稍微特殊的场景&#xff0c;同一条SQL语句&#xff0c;在某些参数下生效…

网站高可用数据

网站高可用数据1、CAP原理&#xff1a;数据一致性&#xff0c;数据可用性&#xff0c;分区耐受性&#xff0c;无法同时满足2、数据备份a、冷备份b、热备份1、同步热备份2、异步热备份3、失效转移a、失效确认b、访问转移c、数据恢复转载于:https://blog.51cto.com/hanchengen/17…

运维工程师常见软件故障_软件故障 软件工程师

运维工程师常见软件故障软件故障 (Software Failure) A failure that shows up when the user recognizes that the software has come to bring to an end to deliver the anticipated result with respect to the specification input values. The user may need to identify…

干掉 Swagger UI,这款神器更好用、更高效!

事情是这样的&#xff1a;今天我们公司的后端说他接口写完了&#xff0c;并分享了一个接口文档给我。用的就是 Swagger UI 自动生成的那种接口文档&#xff0c;就像这种&#xff1a;这种 Swagger UI文档我每次看着就头大&#xff0c;毛病多多查看多级模型时要一级级点开在接口数…

Android UI ActionBar功能-ActionBarProvider的使用

分享功能是很多App都有一个功能&#xff0c;ActionBarProvider可以实现分享功能&#xff1a; 3.0以前的版 本和3.0以后的版 本的区别&#xff1a; public class MainActivity extends Activity {private ShareActionProvider provider;Overrideprotected void onCreate(Bundle …

ruby 类方法与实例方法_Ruby Set相交? 实例方法

ruby 类方法与实例方法Ruby Set相交&#xff1f; 方法 (Ruby Set intersect? Method) intersect?(Set) method is a method which is predefined in Rubys library. You may call this method as an exact opposite of Set.disjoint?() method. With the help of this metho…

面渣逆袭:MyBatis连环20问,这谁顶得住?

大家好&#xff0c;今天我们的主角是MyBatis&#xff0c;作为当前国内最流行的ORM框架&#xff0c;是我们这些crud选手最趁手的工具&#xff0c;赶紧来看看面试都会问哪些问题吧。基础1.说说什么是MyBatis?MyBatis logo先吹一下&#xff1a;Mybatis 是一个半 ORM&#xff08;对…

Wi-Fi 协议和数率?

IEEE 802.11Wi-Fi 协议摘要 协议 频率 信号 最大数据速率 传统 802.11 2.4GHz FHSS 或 DSSS 2Mbps 802.11A 5GHz OFDM 54Mbps 802.11B 2.4GHz 人力资源DSSS 11Mbps 802.11G 2.4GHz OFDM 54Mbps 802.11n 2.4 或 5GHz OFDM 600Mbps(理论值) 802.11AC 5…