zoj 2921 Stock(贪心)

【Dify】PPT生成工具应用 本文介绍了一款自动化PPT生成工具,通过智能接口将文本内容高效转化为结构化演示文档。该系统采用三阶段工作流(内容输入、HTTP请求上传、文件输出),无需复杂操作即可生成专业PPT。工具适用于教学课件、产品发布、企业培训等场景,能显著提升内容表达效率,特别适合初学者快速制作演示材料。文章详细说明了核心节点、应用场景及开发资源,为文本到PPT的自动化转换提供了实用解决方案。 阅读详情


Optiver sponsored problem.

After years of hard work Optiver has developed a mathematical model that allows them to predict wether or not a company will be succesful. This obviously gives them a great advantage on the stock market.

In the past, Optiver made a deal with a big company, which forces them to buy shares of the company according to a fixed schedule. Unfortunately, Optiver's model has determined that the company will go bankrupt after exactly n days, after which their shares will become worthless.

Still, Optiver holds a large number of sell options that allows them to sell some of the shares before the company goes bankrupt. However, there is a limit on the number of shares Optiver can sell every day, and price Optiver receives for a share may vary from day to day. Therefore, it is not immediately clear when Optiver should sell their shares to maximize their profit, so they asked you to write a program to calculcate this.

Input

On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with an integer n (1 <= n <= 100 000): the number of days before the company goes bankrupt.

n lines with three integers xi (0 <= xi <= 100), pi (0 <= pi <= 100) and mi (0 <= mi <= 10 000 000): the number of shares Optiver receives on day i, the (selling) price per share on day i, and the maximum number of shares Optiver can sell on day i, respectively.

Output

For each test case:

One line with the maximum profit Optiver can achieve.

Sample Input

1
6
4 4 2
2 9 3
2 6 3
2 5 9
2 2 2
2 3 3

Sample Output

76


题意:有n张股票,给出每天股票的买进数量,当天的股票价格和当天最大抛出量,第i天得到的股票当天可以不抛,可以留到以后抛。问这n天最多能卖多少钱?

思路:贪心,从后往前贪心,最后一天的股票当然只能在最后一天卖出,第i天的可以在第i天及以后卖出,那么就可以维护一个优先队列来存放第i天及以后的天数中抛出量不为零的日期(价格高的优先),那抛出第i天时先从优先队列中取出价格最高的。



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
//typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 100005

int r[N],p[N],s[N];
int n;


struct stud{
 int p,num;
 friend  bool operator < (stud a,stud b)
    {
    	return a.p<b.p;
	}
};

priority_queue<stud>q;


void solve()
{
	int i,j;
	while(!q.empty()) q.pop();

	int ans=0;

	struct stud cur;

	for(i=n-1;i>=0;i--)
	{
        cur.num=s[i];
        cur.p=p[i];
        q.push(cur);

		while(!q.empty()&&r[i])
		{
		   	 cur=q.top();

		   	 q.pop();

		   	 if(cur.num>r[i])
			 {
			 	ans+=cur.p*r[i];
			 	//pf("%d %d\n",cur.p,r[i]);
			 	cur.num-=r[i];
			 	r[i]=0;
			 	q.push(cur);
			 }
             else
			 {
			 	ans+=cur.p*cur.num;
			 	r[i]-=cur.num;
			 //	pf("%d %d\n",cur.p,cur.num);

			 }
		}

	}

	pf("%d\n",ans);
}
int main()
{
	int i,j,t;
	sf(t);
	while(t--)
	{
		sf(n);
		fre(i,0,n)
		 sfff(r[i],p[i],s[i]);
        solve();
	}
   return 0;

}















windows下使用Nginx搭建Rtmp流媒体服务器,实现视频直播功能 一、环境介绍 操作系统:win10 64位系统 Linux下搭建Nginx搭建Rtmp流媒体服务器方法请看这里:https://blog.youkuaiyun.com/xiaolong1126626497/article/details/105378894 二、流媒体服务器介绍 流媒体服务器的主要功能是以流式协议(RTP/RTSP、MMS、RTMP等)将视频文件传输到客户端,供用户在线观看;也可从视频采集、压缩软件接收实时视频流,再以流式协议直播给客户端。 nginx服务器是开源的高性能的http服务器,反向 阅读详情

相关推荐

Jetson AGX Orin 新手避坑:解决‘找不到nvidia-jetpack包’的完整修复指南

本文详细介绍了Jetson AGX Orin设备在安装JetPack开发套件时遇到的'nvidia-jetpack包缺失'问题的完整解决方案。通过分析问题根源、提供分步修复指南以及系统优化建议,帮助开发者快速解决这一常见问题,充分发挥Jetson AGX Orin的边缘计算性能。

weixin_42520909的博客 460

Stock (zoj 2921 贪心经典)

题意:有n张股票,给出每天股票的买进数量,当天的股票价格和当天最大抛出量,第i天得到的股票当天可以不抛,可以留到以后抛。问这n天最多能卖多少钱? 思路:贪心,从后往前贪心,最后一天的股票当然只能在最后一天卖出,第i天的可以在第i天及以后卖出,那么就可以维护一个优先队列来存放第i天及以后的天数中抛出量不为零的日期(价格高的优先),那抛出第i天时先从优先队列中取出价格最高的。

@you! 989

Qt 5.15.2静态编译避坑实录:MinGW 32位版从源码到Creator配置的全流程踩坑总结

本文详细介绍了Qt 5.15.2 MinGW 32位版本的静态编译全流程,包括环境准备、配置参数优化、编译过程监控及安装后配置。重点解决了静态编译中的常见问题,如参数顺序敏感、路径引号问题等,并提供了性能对比实测数据,帮助开发者高效完成静态编译。

weixin_26749245的博客 271

Stock 贪心经典 Zoj2921

Optiver sponsored problem. After years of hard work Optiver has developed a mathematical model that allows them to predict wether or not a company will be succesful. This obviously gives them a great

每一次AC都是一种感动 478

单细胞基因可视化之热图的根本改造2

我们前面已经说过了单细胞marker/或者其他任意基因的热图的简单修饰(单细胞基因可视化之热图改造修饰1),仅仅是基于颜色和DoHeatmap函数的参数修饰。那么要对热图进行根本的改造,关键点在于提取表达矩阵,然后对分组进行注释,就可以使用heatmap或者ComplexHeatmap来做图了。 首先计算marker基因,然后选择自己需要展示的基因。 library(Seurat) library(stringr) library(dplyr) all.markers <- Find

qq_42090739的博客 6676

使用【阿里云百炼】搭建自己的大模型

本文介绍阿里云百炼大模型平台,其为企业级服务平台,融合通义千问等模型,支持多模态能力,提供一站式工具降低开发门槛。重点讲解智能体应用及大模型搭建步骤,含进入创新应用界面、选模型配参数、输指令、导数据、加载知识库、获取API Key、加样例库、配置MCP,还提及模型调试与多平台发布,并附试用链接,助力企业与开发者快速搭建适配业务的AI模型。

Larry的博客 4738

【贪心】zoj2921 stock

一开始想到是贪心了,以为是每次找出最高价格,然后在前面寻找最小的、次小的...直至所有的股票卖完或者达到卖股票的上限,超时超到死啊。。。。。后来才明白,从最后一个元素开始贪心,并用优先队列进行组织,可达到O(nlgn)的时间复杂度,这回是真的长见识了。。。。 为什么从最后一个开始呢?原因也很简单,最后一天的股票只能在最后一天卖出去,其他天数的股票只能在当天以及以后的天数里卖出去,从这里面

BananaTree 772

DeepSeek 框架和技术栈分析

DeepSeek 诞生于对更高效、更强大的深度学习计算和模型训练的追求。随着深度学习模型的规模不断增大,如大型语言模型(LLMs)和复杂的视觉模型,传统的框架在处理这些大规模模型时面临着性能瓶颈和资源利用效率低下的问题。DeepSeek 旨在解决这些问题,通过优化框架设计和采用先进的技术栈,实现更高效的模型训练和推理,同时降低计算成本。

yournameplease的专栏 1510

zoj-2921 Stock ***

1 /*纯粹转, http://hi.baidu.com/sheep_finalfreedom/blog/item/1fbb2046408dd889b3b7dc4a.html */ 2 /* 3 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2921 4 5 最初以为是DP,后来想通之后发现是非常经典的贪心! 6 ...

weixin_33970449的博客 137

PyTorch深度学习实战(39)——少样本学习(Few-shot Learning)

小样本学习 (Few-shot Learning) 旨在解决在训练集中只有很少样本的情况下进行分类和推理的问题。在小样本学习中,我们希望通过利用已有的少量样本和先验知识来进行泛化,以便在面对新的、未见过的类别时能够做出准确的预测。这就要求模型能够从有限的训练样本中提取出有用的信息,并能够将这些信息应用到新类别的样本中去。在本节中,将介绍孪生、原型和关系网络的原理,并使用 PyTorch 实现孪生网络。

盼小辉丶的博客 1万+

基于深度学习的垃圾邮件识别

垃圾邮件的大量存在严重威胁着电子邮件系统的安全和效率。基于深度学习的垃圾邮件识别技术已经成为目前最有效的解决方案之一。本文将详细介绍使用深度学习技术进行垃圾邮件识别的方法,并提供相应的代码实现。 随着电子邮件的广泛应用,垃圾邮件的数量不断增加,传统的规则和统计方法已经无法满足对垃圾邮件进行准确识别的需求。深度学习技术以其强大的模式识别能力和自动特征提取能力成为解决垃圾邮件识别难题的有效工具。

一键难忘的博客 1093

CF 332 C 贪心

CF 332 C 贪心

左眼皮跳跳 2292

深度学习工具包 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 2970 The lazy programmer(优先队列+贪心)

Language: Default The lazy programmer Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1566   Accepted: 386 Description A new web-design studio, called 

左眼皮跳跳 1389

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

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

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

HDU 1338 Game Prediction 贪心

HDU 1338 Game Prediction 贪心

左眼皮跳跳 1138

HDU 2037 今年暑假不AC

贪心 HDU 2037 今年暑假不AC

左眼皮跳跳 1077

Hot Days Codeforces Round #132 (Div. 2) D(贪心)

Description The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 ≤ i ≤ n) region has

左眼皮跳跳 1057

ZOJ 3019 Puzzle

贪心 ZOJ 3019 Puzzle

左眼皮跳跳 987

zoj 1543 贪心

zoj 1543 Stripies 贪心

左眼皮跳跳 926

POJ 1700 Crossing River(贪心)

V - Crossing River Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1700 Description A group of N people wishes to go across

左眼皮跳跳 795

CSU 1603 Scheduling the final examination(贪心)

1603: Scheduling the final examination Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 58  Solved: 18 [Submit][Status][Web Board] Description For the most of the university students,what t

左眼皮跳跳 764

HDU 1789 贪心

Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in

左眼皮跳跳 711

POJ 3253 Fence Repair(贪心)

Fence Repair Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 29580   Accepted: 9621 Description Farmer John wants to repair a small length of the fence aro

左眼皮跳跳 670

POJ 3262 Protecting the Flowers(贪心)

Language: Default Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4942   Accepted: 1973 Description Farmer John went to cut some w

左眼皮跳跳 645

POJ 3190 Stall Reservations(贪心)

Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3590   Accepted: 1284   Special Judge Description Oh those picky N (1 <= N <= 50,000)

左眼皮跳跳 619
上一篇: HDU 3001 Travelling(状压dp)
下一篇: POJ 2288 Islands and Bridges(状压dp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值