Task(二维关键字不同且有向的贪心思想(有坑点,反向求会wa。。))

c++工厂机器安排(贪心) 题目为: 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 comp... 阅读详情


Link: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): 4606    Accepted Submission(s): 1207


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
 


题意:N台机器,M个任务,机器和任务分别有一个time值,和level值。每台机器上最多只能运行一个任务,而且机器的time值和level值要分别大于等于该任务的值才能做该任务。完成一个任务会获得(500*time+2*level)的价值,求对于给出的机器和任务,能获得的最大价值。

编程思想:贪心。题目很特别的给出了获得金钱的计算公式为500*x+2*y,y<=100,也就是说y怎么样也没有x变化1价值增加的多,所以我们要优先保护x,所以在二级排序的时候先以x,再y,这样就可以在保证个数最大的情况下价值最大了,整个过程还是简单贪心,所以可以按任务时间从大到小排序,然后每个任务找出大于等于该任务难度且与难度最接近(sett.lower_bound(task[i].yi)函数)的机器完成该任务。


AC code:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<set>
#define LL long long
#define MAXN 1000010
using namespace std;
struct node{
	int xi;//时间 
	int yi;//級別 
	bool operator < (const node &b)const
	{
		if(xi!=b.xi)
			return xi>b.xi;
		else
			return yi>b.yi;
	}
}machine[MAXN],task[MAXN];

multiset<int>sett;
multiset<int>::iterator it;
LL ans;
int cnt;
int main()
{
//	freopen("D:\\in.txt","r",stdin);
	int T,i,j,n,m;
    while(~scanf("%d%d",&n,&m))
    {
		sett.clear();
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&machine[i].xi,&machine[i].yi);
		}
		for(i=1;i<=m;i++)
		{
			scanf("%d%d",&task[i].xi,&task[i].yi);
		}
		sort(machine+1,machine+n+1);
		sort(task+1,task+m+1);
		j=1;
		ans=0;
		cnt=0;
		for(i=1;i<=m;i++)
		{
			while(j<=n&&machine[j].xi>=task[i].xi)
			{
				sett.insert(machine[j].yi);
				j++;
			}
			if(sett.empty())
			{
				continue;
			}
			it=sett.lower_bound(task[i].yi);
			if(it!=sett.end())
			{
				ans+=500*(task[i].xi)+2*(task[i].yi);
				cnt++;
				sett.erase(it);
			}
		}
		printf("%d %I64d\n",cnt,ans);
	}
  	return 0;
}


【信息科学与工程学】【数据科学】数据科学领域 第六篇 算法设计 07 堆、栈、表、矩阵、集合、队列、数组、字符串、树、图、动态规划、结构体、元组的算法01 当前段必须包含所有字符的最后出现位置。1. 字符串分割成最多片段2. 基因序列功能域划分3. 文本段落划分4. 音频声道分离5. 图像色彩分区6. 社交网络社群划分7. 蛋白质结构域8. 音乐乐章分段9. 代码模块划分10. 章节划分特征:一次扫描,贪心确定边界。 阅读详情

相关推荐

贪心算法(船只载货问题)

贪心算法,关于船只载货的问题算法。对于处理一维下料、二维下料、甚至三维都有一定的启发性。

工厂机器安排(Java)

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

wowhhhgd的Blog 674

论文解析-sciPENN

用这2个CITE-seq共有的protein作为训练集,分别将他们特有的protein作为测试集,评估sciPENN对CITE-seq数据集中缺失的protein丰度预测准确度。来自Seurat 4 的PBMC数据集,样本被注射水疱性口炎病毒 (VSV) 载体 HIV 疫苗,数据集包含每个样本注射疫苗0天、3天、7天的CITE-seq数据。PBMCs作为训练集,MALT作为测试集,利用scRNA-seq测试17个蛋白质表达水平。Monocyte:随机取4个样本作为训练集,剩余4个样本作为测试集。

weixin_46065198的博客 1028

工厂机器安排(贪心算法)

题目来源:HDOJ 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,

weixin_48345739的博客 2121

离线反激转换器反馈环路设计:从理论到实践的Type II补偿器详解

在开关电源设计中,反馈环路稳定性是决定电源性能与可靠性的核心。其本质是通过补偿网络对功率级的小信号特性进行校正,以构建一个具有足够相位裕度和增益裕度的闭环系统。反激转换器作为一种广泛应用的隔离拓扑,其功率级在连续导通模式(CCM)和非连续导通模式(DCM)下呈现不同的零极点特性,这直接决定了补偿器的选型。Type II补偿器因其传递函数中固有的积分环节、低频零点与高频极点,恰好能与反激功率级的1P2Z(一个极点、两个零点)特性形成互补,有效塑造理想的回路增益曲线,实现快速稳定的动态响应。本文聚焦于采用TL4

weixin_30162121的博客 518

SMR实战指南:从GWAS数据到eQTL分析的完整流程

本文提供了基于汇总数据的孟德尔随机化(SMR)实战指南,详细解析了如何从GWAS汇总数据出发,整合eQTL数据,完成从数据准备、BESD格式转换到最终SMR与HEIDI分析的完整流程。文章重点阐述了核心操作步骤、常见避坑技巧与结果解读,旨在帮助遗传学研究者高效掌握这一分析基因表达与复杂性状潜在因果关系的强大工具。

weixin_29246195的博客 1095

二维贪心问题

二维贪心问题常见于数组排序等操作中,它往往要求所得结果同时满足两个方面的条件,这两个条件相互之间存在某种关联,可以相互影响。如果仅在一个维度上应用贪心算法很容易顾此失彼,难以得出正确答案。

m0_72379992的博客 524

手把手教你使用ConvNeXt训练自己数据集和推理,ConvNeXt模型训练(CVPR 2022),一个能挑战 Vision Transformer 的卷积神经网络,含完整代码和数据集

手把手教你使用ConvNeXt训练自己数据集和推理,ConvNeXt模型训练(CVPR 2022),一个能挑战 Vision Transformer 的卷积神经网络,含完整代码和数据集

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 1477

二、stl ,模拟,贪心等 [Cloned] R - 贪心

原题: 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 comp...

npuyan的博客 307

【虚幻引擎UE】UE5 可编辑动态样条线轨迹及AI跟随路径移动(含工程源码)

【虚幻引擎UE】可编辑动态样条线轨迹及AI跟随路径移动

灵境引路人 6231

你以为你懂 Java 反射?看了这篇源码分析,我发现我以前都错了

摘要:本文讲述了一次生产环境Metaspace内存溢出的故障排查经历。事故源于一个通用数据导出功能中频繁使用反射调用method.invoke(),触发了JVM的"膨胀机制":当同一Method对象调用超过15次时,JVM会动态生成GeneratedMethodAccessor类,导致Metaspace被撑爆。文章分析了问题根源在于循环中反复调用getMethods()创建新Method对象,并提出了三种解决方案:缓存Method对象、改用MapStruct/MethodHandle工具

BUG猿的博客 772

贪心算法(两个维度维权问题)

贪心算法(两个维度维权问题)1.分发糖果2. 根据身高重建队列 1.分发糖果 贪心算法(两个维度维权问题) 1.先从左向右遍历,当右面孩子的评分大于左面孩子的,右面孩子糖果数等于左面孩子糖果数加一。 2.再从右向左遍历,只要左边比右边大,此时左边的糖果(符合比它左边大)和右边糖果数加一二者的最大值。这样才符合它比它左边的大,也比它右边的大。 class Solution { public int candy(int[] ratings) { int[] candyVec = n

weixin_53310322的博客 871

YOLO26 改进 - 注意力机制 | Mask Attention掩码注意力,可学习掩码矩阵破解低分辨率特征提取难题 | 2025 预印

本文提出了用于低分辨率图像分割的MaskAttn - UNet框架,并将其核心的掩码注意力机制集成到YOLO26中。传统U - Net类模型难以捕捉全局关联,Transformer类模型计算量大,而掩码注意力机制通过可学习的掩码,让模型选择性关注重要区域,融合了卷积的局部效率和注意力的全局视野。其工作流程包括特征适配、掩码生成、定向注意力计算和特征融合。我们将掩码注意力机制代码集成到YOLO26中。

魔改工程师的博客 838

【算法设计与分析】贪心算法

一、贪心算法 在求最优解问题的过程中,依据某种贪心标准,从问题的初始状态出发,直接去求每一步的最优解,通过若干次的贪心选择,最终得出整个问题的最优解,这种求解方法就是贪心算法。 从贪心算法的定义可以看出,贪心算法不是从整体上考虑问题,它所做出的选择只是在某种意义上的局部最优解,而由问题自身的特性决定了该题运用贪心算法可以得到最优解。 如果一个问题可以同时用几种方法解决,贪心算法应该是最好的选择之一。 二、贪心算法的理论基础 贪心算法是一种在每一步选择中都采取在当前状态下最好或最优的选择,希望得到结

a765528534的博客 687

6、 实时家禽健康识别与疾病检测系统的深入解析

本文深入解析了一种基于物联网的实时家禽健康识别与疾病检测系统,结合图像分析和音频分析技术,能够有效识别病鸡并防止疾病传播。文章详细介绍了系统的测试环境、数据采集与预处理方法、图像与音频分析流程,并对系统性能进行了全面评估。最后提出了未来改进方向,包括多模态融合、深度学习应用及实时性优化等。

weixin_28840811的博客 191

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces 798D Mike and distribution(二维贪心)

D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has always been thinking abou

yasolx的博客 1645

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

HDU 4864(贪心)

TaskTime Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Problem DescriptionToday the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile...

niuniu0205的博客 270

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

二维装箱贪心算法matlab,2018搜狐编程题-贪心算法-二维装箱问题

题目描述一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。这些产品通常使用一个 6*6*h 的长方体包裹包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的包裹数量。他们很需要有一个好的程序帮他们解决这个问题从而节省费用。现在这个程序由你来设计。输入输入文件包括几行,每一...

weixin_36272649的博客 1084

贪心策略 HDU - 4864 Task

DescriptionToday 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 canno...

笑彪夕的博客 860

Task

Problem A : Task From:HDU, 4864 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 mach

xuehuhu1的专栏 457

task(贪心)

Task 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’

ljyanjy 657

hdu 4864 Task

Task Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2108    Accepted Submission(s): 536 Problem Description Today the company has

浮躁的人,终究一事无成! 1703

两个费用的贪心(HDOJ 4864)

Task Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7328    Accepted Submission(s): 1939 Problem Description Today the company

Eminem1147的博客 529

贪心 (任务与机器)

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

OJBFOWE的博客 610

HDU 4864 Task 贪心 难题

D - Task Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description Today the company has m tasks to complete. The ith task need xi minutes to complete. M

Katapeltes 709

hdu4864 task

#include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define REP(i,a,b) for(int i=a;i<=b;++i) #define mset(a) memset(a,0,

ocgcn2010的专栏 645
上一篇: hdu4268 Alice and Bob(二维贪心的固定思想 STL的multiset的二分查找函数实现)
下一篇: Couple doubi(费马小定理或打表找规律+简单博弈)
林下的码路
博客等级 码龄12年 295粉丝 506原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值