|洛谷|堆|P3045 [USACO12FEB]牛券Cow Coupons

2021春 算法复习 [USACO12FEB]Cow Coupons G 贪心+堆。首先在优惠券没用完的情况下按优惠价从小到大全部买进。对于没购买的奶牛i,若想加购,可花费原价Pi,或挪用另一只奶牛j的优惠券,即花费Ci+Pj-Cj。故维护三个小根堆(P,C,P-C)即可。(代码略丑 #include<iostream> #include<algorithm> using namespace std; int n,k,n1,n2,n3,ans,a[50010],b[50010],h1[5001. 阅读详情

https://www.luogu.org/problem/show?pid=3045

把c作为关键字放入一个小根堆,在堆里买k个牛,然后再把这个小根堆里的牛放到另一个以p作为关键字的小根堆,买牛直到没钱

注意m要long long

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int n,k;
long long m,ans = 0;
struct cow
{
       int p,c;
};
struct cmp1
{
       bool operator()(cow a, cow b)
       {
            return a.c>b.c;
       }
};
struct cmp2
{
       bool operator()(cow a, cow b)
       {
            return a.p>b.p;
       }
};
priority_queue<cow, vector<cow>, cmp1> p1;
priority_queue<cow, vector<cow>, cmp2> p2;
int main()
{
   scanf("%d%d%lld", &n, &k ,&m);
   for (int i=1;i<=n;i++)
   {
       cow c;
       scanf("%d%d", &c.p, &c.c);
       p1.push(c);
   }
   while (k>0&&!p1.empty())
   {
         if (m-p1.top().c>=0)
         {
            m -= p1.top().c; p1.pop(); ans++; k--;
         } else break;
   }
   while (!p1.empty()) {p2.push(p1.top()); p1.pop();   }   
   while (!p2.empty())
   {
         if (m-p2.top().p>=0)
         {
            m -= p2.top().p; p2.pop(); ans++;
         } else break;
   }
   printf("%lld\n", ans);
   system("pause");
    return 0;
}


别再用老古董了!手把手教你排查并修复jQuery 1.7.2任意文件读取漏洞(附修复脚本) 本文详细介绍了jQuery 1.7.2任意文件读取漏洞的排查与修复方法,包括漏洞影响评估、紧急缓解措施、彻底修复方案及持续监控策略。通过实战指南和自动化脚本,帮助开发者快速应对这一高危漏洞,确保系统安全。 阅读详情

相关推荐

Eigen 直线拟合/曲线拟合/圆拟合/椭圆拟合

使用Eigen库进行直线拟合是数据分析和科学计算中的常见任务,主要通过最小二乘法实现。该代码演示了二维空间中的直线拟合,输出斜率和截距。

深之JohnChen的专栏 1604

洛谷P3045 [USACO12FEB] Cow Coupons G(堆,反悔贪心)

这里,每一个物品用优惠卷节省的钱可以使用优先队列。个最小的优惠假,再考虑如何反悔。表示一个已经使用了优惠卷的物品,表示一个未购买的物品。表示现在用了多少钱,如果要换成用原价购买。

weixin_74754298的博客 1015

DP3(3D Diffusion Policy)算法详解:从点云感知到扩散动作生成

DP3 的全称是:DP3 = 3D Diffusion Policy\boxed{\text{DP3 = 3D Diffusion Policy}}DP3 = 3D Diffusion Policy​对应论文题目是:3D Diffusion Policy: Generalizable Visuomotor Policy Learning via Simple 3D Representations该工作发表于 Robotics: Science and Systems(RSS)2024。DP3 是一种面向机器

u013250861的博客 361

[USACO12FEB]牛券Cow Coupons

嘟嘟嘟 这其实是一道贪心题,而不是dp。 首先我们贪心的取有优惠券中价值最小的,并把这些东西都放在优先队列里,然后看[k + 1, n]中,有些东西使用了优惠券减的价钱是否比[1, k]中用了优惠券的物品更划算,是的话就更新。 1 #include<cstdio> 2 #include<iostream> 3 #include<...

weixin_30468137的博客 103

机器人关节电机发热难题:从工程化角度拆解热管理解决方案(下)

摘要:本文系统分析了机器人关节电机与驱动系统的热管理方案,重点解决局部热点问题。针对不同功率场景提出了热管/均热板散热(适用于中小功率)和液冷散热(适用于高功率)的具体实施方案,详细比较了结构参数、材料选择、安装工艺和散热效果。特别强调了电机-驱动协同热管理的重要性,提出"工况联动+热路径共享"的核心理念,包括一体化散热结构设计和动态控制策略。最后介绍了热仿真与测试验证方法,确保方案的有效落地。通过系统级热管理,可显著降低温升(热点区域降温30-60℃),同时优化体积和能耗。

bother3000的博客 3335

机械臂的运动学分析-工业机器人

机械臂的运动学是研究机械臂各连杆坐标系之间的运动关系,是对机械臂进行运动控制的基础。本章分析了所设计的六自由度机械臂的运动学。理论上六自由度机械臂的工作空间是一个近似球形区域,能够覆盖机械臂所在的位置,但由于机械臂关节的运动范围受到限制,机械臂末端会存在一些不能到达的工作死区,使得机械臂的工作范围和灵活性受到限制。理论上六自由度机械臂的工作空间是一个近似球形区域,能够覆盖机械臂所在的位置,但由于机械臂关节的运动范围受到限制,机械臂末端会存在一些不能到达的工作死区,使得机械臂的工作范围和灵活性受到限制。

qq_59137727的博客 6650

【洛谷 P2085】最小函数值【堆】

解题思路 所以我们建一个大根堆,存最小的数到第m小的数,第m小的数就理所当然的是堆顶了。 每次我们只需要比较新加进来的数比堆顶大还是比堆顶小。 如果比堆顶小,将原来的堆顶丢掉,将新的数塞进去; 如若比堆顶大,根据该题题意,a>0&&b>0,函数对称轴x=−b2∗ax=-\frac{b}{2*a}x=−2∗ab​/恒小于0,可以得出,y在x>0x>0x>0时是单调递增的,所以接下来的函数值y只会大不会小,可以直接breakbreakbreak掉了 由于我们存储..

在人间贩卖声音 525

【客户案例】母婴行业头部品牌是如何做私域的

各品牌争相跑马圈地,想方设法圈住流量,建立品牌资产;私域运营是一项“重人力”的工作,在传统的品牌运营过程中,私域操盘手经常会由于一对多导致无法兼顾,只能通过提高触达次数的方式加大漏斗,这样难以让每个社群都发挥出应有的价值,甚至还会导致一定程度的用户流失。除了宝妈身份外激发的用户认同感、亲密度外,KOC们作为产品的使用者,自由选择的推品和自由创作的推广文案都更具有真实性、代表性,能够极大程度激发群友们的信任感,从而愿意为产品买单,转化复购水到渠成。不同阶段的宝妈,母婴知识的储存量和经验是不同的,K品牌还会。.

圈量SCRM系统-企微营销工具-私域流量运营软件 950

洛谷 P2278 03湖南 操作系统

堆

sdfzrlt的博客 914

YOLO26模型应用过程中的报错处理及疑问解答,涉及环境搭建、模型训练、模块改进、论文写作

本文记录了YOLO26模型的这一系列过程中可能发生的问题,以及大家非常关心的问题,这里统一做了一个记录和解答。

Limiiiing的博客 245

Windows 11 WSL2环境下OpenClaw部署的兼容性问题分析与解决方案研究

本文研究了OpenClaw在Windows 11 WSL2环境下的部署方案。WSL2通过无缝集成Linux与Windows系统,为OpenClaw提供了良好的运行环境,支持GPU加速和跨平台开发。文章详细分析了硬件配置要求(推荐8核CPU/16GB内存/NVMe SSD)、系统选择(Windows 11 Pro+Ubuntu 22.04)以及部署步骤,包括WSL2启用、Linux发行版安装、Python/Node.js/Redis等依赖配置。通过优化.wslconfig文件参数(如内存分

博客 2285

洛谷P3045 [USACO12FEB]牛券Cow Coupons

题目:洛谷P3045 [USACO12FEB]牛券Cow Coupons 思路: 贪心 假设先用完所有优惠券,则只有两种决策:以原价购买未选物品中价格最低的;以最低代价退回当前用的一张优惠券,再以优惠价购买未选物品中优惠价最低的。 回退(反悔)操作可以用堆实现,具体实现: 用三个小根堆h1、h2、h3,分别存储未选物品的原价及编号、未选物品的优惠价及编号、已选物品退回优惠券的代价。 每次...

denge2160的博客 439

Linux下使用Nginx搭建Rtmp流媒体服务器,实现视频直播功能

一、环境介绍 操作系统:虚拟机运行的Ubuntu18.04 64位系统 二、流媒体服务器介绍 百度百科: 流媒体指以流方式在网络中传送音频、视频和多媒体文件的媒体形式。相对于下载后观看的网络播放形式而言,流媒体的典型特征是把连续的音频和视频信息压缩后放到网络服务器上,用户边下载边观看,而不必等待整个文件下载完毕。由于流媒体技术的优越性,该技术广泛应用于视频点播、视频会议、远程教育、远程医疗和...

7145

P3045 [USACO12FEB]牛券Cow Coupons

洛谷 P3045 [USACO12FEB]牛券Cow Coupons 题目描述 一个错误的贪心思路:设优惠券有无数张,然后我们贪心去选,这样就会得到94的好成绩。(数据真水 #include<algorithm> #include<iostream> #include<cstdio> #include<queue> #define ll l...

weixin_30527323的博客 281

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

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

[USACO12FEB]牛券Cow Coupons (洛谷P3045)

[USACO12FEB]牛券Cow Coupons 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). ...

不知所云的博客 621

深度学习工具包 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")

P3045 [USACO12FEB] Cow Coupons G 题解

原价,优惠,差价(本来选优惠,更改为选原价的差价)。假设优惠券都用完了:如果此时选原价比优惠+差价便宜,就选原价。如果选优惠+差价优,就选优惠+差价,并且把这个的优惠的差价加入差价堆,代表也是可以反悔的。贪心不一定是最优解,通过撤销(反悔)操作来获得最优解。刚开始选最小的,但有时候不给最小的用优惠券,而是给后面用,可能更优。,每头奶牛只能用一次。张优惠券,用优惠券购买第。选的时候注意标注哪些选过了。,代表不用补差价,也就是。的钱最多可以买多少?

MYJ_aiie的博客 408

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

【bzoj2590】【洛谷P3045】【USACO12FEB】牛券Cow Coupons

题目描述Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9)

infinity_edge的博客 996

【洛谷2085】最小函数值(堆)

点此看题面 大致题意:给你NNN个形如Fi(x)=Aix2+Bix+Ci(x∈N∗)Fi(x)=Aix2+Bix+Ci(x∈N∗)F_i(x)=A_ix^2+B_ix+C_i(x∈N^*)的函数,请你求出所有函数的所有函数值中最小的前mmm个值。 最暴力的解法 显然,我们可以发现...

CXR的博客 636

[USACO12FEB]Cow IDs

题意:输出第n个不含前导0且1的个数为k的二进制串。 这题和之前一道题类似:G:aab aba baa k=1的情况比较容易考虑,对于任意的n只要在1后面添加若干个零。 对于k>1的情况,先把首位的1拿出来,再讨论剩余k-1个1的分布。 可以枚举串长度为k,k+1,k+2,k+3… L。要解决这个题,首先要知道 这个串的长度,也就是说至少多少位01才能表示出第n种情况。也不难想, 直接判断前面组合数的前缀和,直到某个前缀不小于n。 #include <iostream> #include.

zw201909250425的博客 203

洛谷 P3378 【模板】堆

洛谷 P3378 【模板】堆 洛谷 P3378 【模板】堆 菜鸟生成记(90) 复习一下数据结构的堆排序,顺带复习一下堆,在洛谷找个板子题练一下,还行; 这一题还可以用优先队列priorityqueue,STL yyds [手写堆] #include<iostream> #include<stdio.h> using namespace std; const int N=1e6+10; int a[N]; void heap1(int *a,int rt,int n) {//删除堆顶

Thy__father的博客 894

洛谷 P1801 黑匣子_NOI导刊2010提高(06)

堆

sdfzrlt的博客 844

洛谷 堆专题 序列合并

题目描述 有两个长度都是N的序列A和B,在A和B中各取一个数相加可以得到N^2个和,求这N^2个和中最小的N个。 输入输出格式 输入格式: 第一行一个正整数N; 第二行N个整数Ai,满足Ai 第三行N个整数Bi, 满足Bi 【数据规模】 对于50%的数据中,满足1 对于100%的数据中,满足1 输出格式: 输出仅一行

masterwater的博客 791

[USACO12FEB] 牛券Cow Coupons

来了来了,贪心来了。话说写不出来题就去贪心啦~ 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). ...

weixin_30664615的博客 254
上一篇: |洛谷|堆|P1631 序列合并
下一篇: |洛谷|NOIP2015|堆|P2672 推销员
NotFound1
博客等级 码龄10年 20粉丝 290原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值