poj1456

POJ1328——Radar Installation、POJ1042——Gone Fishing、POJ1456——Supermarket(贪心) 例如,考虑乘积 Prod={a,b,c,d},其中 (pa,da)=(50,2),(pb,db)=(10,1),(pc,dc)=(20,2) 和 (pd,dd)=(30,1)。这是一个典型的区间覆盖问题。可以将问题转化为在不同的终止湖的情况下,如何分配剩余的钓鱼时间,使得钓到的鱼总数最大。一组产品以整数 0 <= n <= 10000 开头,这是集合中的产品数量,然后是 n 对整数 pi di,1 <= pi <= 10000 和 1 <= di <= 10000,指定第 i 个产品的利润和销售截止日期。 阅读详情

题目大意

给你一个超市,每个物品价格为p,过d天就过期了,每天最多卖一个物品,问最大收益。

解析:用到一个很神奇的并查集,先把价格排一下序,有一个很简单的结论,对于每一个要卖出的物品,能拖就拖,把时间让给期限更短的物品。那么对于物品i,如果它的期限为d,就查询d的树根r,如果r>0,就把物品i在第r天卖出并记录答案,然后把r和r-1合并(令r为r-1的儿子)。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct point
{
	int p;
	int d;
}a[10010];
int n,ans;
int father[10010];
int cmp(point a1,point a2)
{
	return a1.p>a2.p;
}
int find(int x)
{
	if(x==father[x])
		return x;
	return father[x]=find(father[x]);
}
void unionn(int x,int y)
{
	father[x]=y;
}
int main()
{
	while(scanf("%d",&n)==1)
	{
		ans=0;
		int maxn=0;
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].p,&a[i].d);
			maxn=max(maxn,a[i].d);
		}	
		sort(a+1,a+1+n,cmp);
		for(int i=1;i<=maxn;i++)
			father[i]=i;
		for(int i=1;i<=n;i++)
		{
			int r=find(a[i].d);
			if(find(r)>0)
			{
				unionn(r,r-1);
				ans+=a[i].p;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


POJ---1456.Supermarket测试数据及答案 POJ---1456.Supermarket测试数据及答案,题目描述:A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σx∈Sellpx. An optimal selling schedule is a schedule with a maximum profit. For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80. 立即下载

相关推荐

手机拍照也能玩高光谱?教你用TensorFlow Lite在Android上实现实时RGB转高光谱

本文介绍了如何利用TensorFlow Lite在Android设备上实现实时RGB到高光谱的图像重构技术。通过深度学习模型优化和移动端部署策略,使智能手机具备专业级光谱分析能力,适用于农业检测、化妆品分析等多个领域。

weixin_29091105的博客 246

poj1456(贪心,并查集(不要掉进dp的陷阱))

题目:https://vjudge.net/problem/POJ-1456 这题不能用dp来做。。。因为底线在明天的物品也可以放在今天来卖,而且题目中的底线时间可以使断续的,所以浪费很多计算而且十分复杂。   正解是用贪心,用上并查集,就可以只要遍历一次即可得到答案。并查集也可以用数组遍历时间相同的统一修改日期(等于goods[i].d的所有商品的日期统一向前移动一天)也可以,但是如果并查...

fx714848657的博客 957

偷懒必备:3种方法快速移植MFC界面资源(含.rc文件打不开解决方案)

本文针对MFC桌面应用开发,详细介绍了三种快速移植界面资源的实战方法:直接编辑.rc文件、利用Visual Studio“添加现有项”进行可视化挂载,以及双实例拖拽应急方案。文章重点剖析了.rc文件无法打开的常见问题,提供了通过修复rc.exe等关键文件来根治此问题的解决方案,帮助开发者高效复用资源,规避ID冲突等陷阱。

weixin_28358083的博客 273

POJ 1456(贪心+并查集)

题目链接:http://poj.org/problem?id=1456 题目大意:给n个商品,每个商品有利润pi和过期时间di,每天只能卖一个商品,过期的不能再卖,求如何安排每天卖的东西使收益最大。 题目思路:先将利润从大到小排序,由于每个物品卖的越迟,给其他物品留下的空间也就越多,所以需要将物品放在能卖的最后一天卖。建立并查集,维护每个点最后一个可以卖的地方,每卖出一个就让当前点...

smilestruggler_Fly To Higher 322

微信小程序协同工作和发布

微信小程序协同工作和发布

qq_53114527的博客 1620

黑群晖DSM7.0.1物理机安装教程

使用芯片无忧工具,查看U盘的和。使用,格式化U盘。使用镜像写入工具,把引导写入U盘。修改文件,可以使用工具把文件复制到桌面,通过修改好之后,拖进这个界面中。或者在电脑中,查看U盘,打开U盘中的文件直接修改。具体修改内容如下:PID修改为U盘的PIDVID修改为U盘的VID默认只有mac1=a8412083CB52 mac2=0a11323D47F7 ,增加:mac3=a15823C08000 mac4=a23C04158B52 mac5=82a002524158 mac6=38233052415aS

JingLisen的博客 2万+

poj1456-贪心+小根堆

http://poj.org/problem?id=1456 大意:给出n个物品的价值和过期时间,问如何安排售出时间可以使得价值和最大。 思路: 贪心策略:在每件物品过期时卖出可以获得最大值。 对所有物品按过期时间从小到大排序,维护一个小根堆,节点值为物品价值。 小根堆的大小就是已经过去的天数,依次判断每个数和小根堆的大小,如果当前数的过期时间小于等于堆的大小,那再判断当前数的价值和堆顶的价值,如果比堆顶值大,则删除堆顶元素,并插入当前数的价值。如果过期时间大,则直接插入。 最后堆内剩余的元素都

qq_46653910的博客 240

告别裸机:在FreeRTOS上为STM32移植SOEM EtherCAT主站的思路与实战

本文详细介绍了在FreeRTOS环境下为STM32移植SOEM EtherCAT主站的工程实践。通过重构任务调度模型、优化内存管理和中断响应,成功将通信周期抖动控制在±100ns以内,满足工业控制系统的严苛实时性要求。文章包含完整的移植策略、性能优化方法和实测数据,为开发者提供了一套可靠的EtherCAT主站解决方案。

weixin_30342363的博客 388

Poj 1456 (并查集)(贪心)(优化队列)

这道题刚开始读错题目还以为超级水体,后来发现是一道贪心~ 可能是数据太水了,用了很简单粗暴的贪心就过了。 先贴上贪心,后面再来试别的方法好了,举一反三咯。 一共贴了三种不同的代码,前面两个是贪心,最后面是第二种的并查集优化版

hi_just_do_it的博客 408

PCB_Project.PrjPcb 4 Not in version control

Altium Designer中PCB项目出现"NOT in version control"错误的解决方法:1. 禁用不需要的版本控制集成(DXP→Preferences→Version Control);2. 清理项目缓存(Projects面板右键→Clean Project);3. 检查文件读写权限;4. 如无效可新建项目重新添加文件。如需使用SVN版本控制,需正确配置SVN客户端路径,创建或连接SVN仓库,并将项目文件提交至版本控制系统。注意新建SVN仓库必须使用空目录,建议使用

whm128的博客 1596

MTK-Android12开机应用自启需求-自定义原生Launcher3 主界面布局图标

MTK平台 Android12 版本 上实现 开机应用自启需求-自定义原生Launcher3 主界面布局图标。添加一个属性定义即可,如下:这里自定义一个属性目的是为了在加载Launcher3启动时候从属性获取需要自启动应用的包名,可以扩展动态替换 自启动包名。这里有两种方案,要么在Launcher3里面实现,要么在系统服务里面在开机时候启动第三方一次。这里强烈建议在Launcher3中去实现,体验效果更好。// 第一步:定义属性,// 第二步:在onCreate 方法中获取属性并启动应用。

十年饮冰,难凉热血 1377

poj1456(两种做法)

带时限的作业排序~~ #include #include #include #include using namespace std; struct node { int p; int t; }; node a[10005]; int visit[10005]; int cmp(node c,node d)//按照收益从大到小,相同收益则时间后的在前 {

fengsigaoju的博客 628

【微服务】Spring Aop原理深入解析

spring原理深度解析

congge 1万+

超市POJ1456

超市POJ1456 思路 题干在这:POJ1456 先按照过期时间由小到大排序,然后建立一个优先队列(利润的小根堆),挨个商品询问。如果商品过期时间大于队列中元素,直接入队,否则只留下和堆顶之中利润较大的。询问完后堆中利润之和就是答案 ac代码 include<cstdio> #include<iostream> #include<algorithm> #inc...

没有自旋的π介子 232

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ1456题解

POJ1456Supermarket

alexmecher的博客 428

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

POJ 1456 Supermarket题解

[原题地址](http://poj.org/problem?id=1456 蒟蒻想了很久,终于做出来了,这个题目应该要用结构体来解决 再排序,自定义一个cmp函数 // while(~scanf("%d %d",…) == ! =EOF ;再while循环里面用b来记录date的最大值,用数组a[1005];来储存利润,最后累加输出,完事,上代码分析 #include <iostrea...

fredvioce的博客 353

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

【POJ 1456】 Supermarket

【题目链接】 http://poj.org/problem?id=1456 【算法】 贪心 + 堆 【代码】 #include <algorithm> #include <bitset> #include <cctype> #include <cerrno&...

214

【POJ 1456 --- Supermarket】贪心

【POJ 1456 --- Supermarket】贪心 题目来源:点击进入【POJ 1456 — Supermarket】 Description A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is ...

来日浅谈的博客 457

POJ 1456 Supermarket

POJ 1456 Supermarket 题解题目大意:给定N个商品,每个商品有利润 Pi 和过期时间 Di ,每天只能卖一个商品,过期商品不能再卖,求如何安排每天的商                   品,可以使收益最大。 【网址:点击打开链接】主要思路:先将商品按照过期日期从小到大sort一遍。                 建立一个小根堆Q【用于存当前的利润】              ...

xjweiyb的博客 227

【poj1456 】supermarket

贪心

sdfzchy的博客 349

POJ1456 Supermarket 并查集

欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - POJ1456 题意概括   一家超市,要卖出N种物品(每种物品各一个),每种物品都有一个卖出截止日期Di(在该日期之前卖出可以获得收益,否则就无法卖出),且每种物品被卖出都有一个收益值Pi. 卖出每个物品需要耗时1天,且任一时刻只能卖出一个物品。给出这N种物品的Di和Pi,求最大收益值。 ...

weixin_30553837的博客 111

POJ1456:Supermarket

浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1456 把物品按照时间排序,显然\(t\)天就只能卖\(t\)个物品。 所以我们把物品一个一个扔进堆里,当某天要卖的物品超过当前天数的时候一直把最小值从堆里弹出即可。 最后堆里剩下的元素就是要卖的元素。 时间复杂度:\(O(...

aga28832的博客 96

poj 1456 Supermarket

点击打开链接poj 1456 思路: 贪心+并查集 分析: 1 题目的意思是给定n个物品的利润和出售的最后时间,求最大的利润 2 比较明显的贪心问题,按照利润排序,假设当前是第i个物品,那么利润为pi出售的时间为di,那么假设di还没有物品销售那么肯定先销售第i个物品,否则找di~1这些时间里面是否有没有销售物品 3 如果按照2的思路做法最坏的情况是O(n^2),但是数据比较弱可以过。但...

我是传奇 216

[POJ 1456]Supermarket[贪心][优先队列or并查集优化]

题目链接:[POJ 1456]Supermarket[贪心][优先队列or并查集优化] 题意分析: 给出若干个商品,每个都有自己的销售截至日期,每天只能销售一个,每销售一个都能得到钱,问:最多能挣到多少钱? 解题思路: 这里可以使用贪心的思路。从末尾往前面数日期,如果当天有商品截止,就把这些商品全都放入优先队列,然后卖出价值最大的那一个;如果当天没有商品截止,就去卖优先队列里价值最大的那个

闲停 773

【ACM】POJ 1456 Supermarket

题目链接:http://poj.org/problem?id=1456题意:有n件商品,告诉其销售利润和销售截止日期,问怎么卖使利润最大解题思路:典型的贪心算法,定义一个结构体数组,内存利润和时间,按利润从大到小进行排序,若利润相同就按时间从大到小进行排序。若该天已被占用,则向前寻找未被占用的日期,直至日期为0。代码:#include &lt;iostream&gt; #include &lt;...

要继续努力的孤独的博客 154
上一篇: 软件包管理器
下一篇: 洛谷P1502 窗口的星星
Slr2002
博客等级 码龄9年 3粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值