POJ 1017 Packets(简单贪心)

【题解】POJ 1017 Packets(贪心) POJ 1017 Packets 原题 https://vjudge.net/problem/POJ-1017 工厂生产的产品均为方形包装,包装高度为h,尺寸为1*1、2*2、3*3、4*4、5*5、6*6。这些产品总是以与产品高度h相同,尺寸为6*6的方形包裹寄给客户。由于费用,这是利益的工厂和客户的利益,以减少包裹的数量,从工厂交付订购的产品给客户。一个好的程序解决了寻找最小数量的包裹的问题,根据订单交付给定的产品将节省大量的钱。你被要求编写这样一个程序。 Input文件由指定订单的几行代码组成。 阅读详情

Packets
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu
Submit Status

Description
A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

Input
The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size 1*1 to the biggest size 6*6. The end of the input file is indicated by the line containing six zeros.

Output
The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last “null” line of the input file.

Sample Input

0 0 4 0 0 1
7 5 1 0 0 0
0 0 0 0 0 0

Sample Output

2
1

题目大意: 所有的箱子都是6*6尺寸的,但是物品有1*1,2*2,3*3,4*4,5*5以及6*6尺寸的,要求把所有的物品放进箱子中,求最少需要多少箱子。

题目思路,对于6*6,5*5以及4*4尺寸的物品每个物品需要占有一个箱子,对于3*3的物品一个箱子可以放4个,2*2的物品箱子可以放9个,1*1的可以放36个。采用面积统计1*1箱子的空位,采用向上去整的方法统计箱子。

AC代码

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int box[8];
int num[5]={0,5,3,1};
int main()
{
    while(1)
    {
        int ant=0;
        for(int i=1;i<=6;i++){
            scanf("%d",&box[i]);
            ant+=box[i];
        }
        if(ant==0) break;
        int sum=0;///所需箱子个数
        sum=box[6]+box[5]+box[4]+(box[3]+3)/4;
        int x2=box[4]*5+num[box[3]%4];  ///统计所有的大物品放进箱子中后a2物品的空位子有多少
        if(box[2]>x2) sum+=(box[2]-x2+8)/9;
        int x1=sum*36-box[6]*36-box[5]*25-box[4]*16-box[3]*9-box[2]*4;  ///求a1的空位子,只需要统计剩余的面积即可
        if(box[1]>x1) sum+=(box[1]-x1+35)/36;
        printf("%d\n",sum);
    }
    return 0;
}
从传统扫描到SSN:Tessent数据包技术如何减少90%测试时间 本文深入探讨了Tessent流式扫描网络(SSN)如何通过其核心的数据包技术,彻底改变芯片测试范式。该技术将测试数据封装成标准化数据包,在共享总线上进行智能路由与分发,实现了动态带宽分配与核心独立测试,从而将复杂SoC(如AI芯片)的总体测试时间大幅削减90%,并显著提升测试灵活性与可扩展性。 阅读详情

相关推荐

PVE 9.0 保姆级安装及优化教程(换源、网络配置、远程唤醒等)【基础篇】

最近,Proxmox VE 推出了基于 Debian 13 的 9.0 版本。正巧我手头有一台闲置的老电脑,与其闲置,不如装上 PVE,让它化身 All in One,继续发挥它的余热。G4560 算是一颗 NAS 神 U,十几元的售价就能有双核四线程,比起什么 J1900 不知道强到哪里去了,尽管定位上是奔腾处理器,但性能甚至能和同代的酷睿 i3-7100 掰掰手腕,并且它还自带 HD 610 的核显,对于解码的支持也还不错。

zc_mk的博客 7511

POJ 1017——Packets

题目链接:http://poj.org/problem?id=1017高只是摆设,题目只是平面填图,翻译过来就是,有1*1,2*2,3*3,4*4,5*5,6*6六种纸板,给出这几个面板的数量,问最少需要多少个6*6纸框才能装完,不才,只能一步一步模拟。思路:6*6只能单独装成一个,一个5*5可以附带11个1*1,一个4*4可以附带5个2*2或若干个2*2和若干个1*1,3*3的因为可能造成空缺,...

sifangege的博客 282

【学习体会】Lighttools8.4.0:简单光学系统实例

添加球型光源(SphereSource)和表面接收器: 对光线模拟的参数进行设置: 光线追踪-模拟输入 要追踪的光线总数,决定模拟的准确度,总数越多,准确度越高,当然耗时更多 预览光线数量是模拟之后可以看到的示意光线(黑线),一般是100~1000,随意设置 点击,开始模拟: (模拟结果) 如果光线太多,则会出现,可以看到剩余时间 照度分析: 分析-照度显示-光栅图表 ...

LeonJin的博客 1万+

POJ 1017 Packets (典型的贪心算法)

地址:http://poj.org/problem?id=1017 翻译:http://poj.grids.cn/practice/1017/ 思路:贪心算法 , 其实这道题的关键就是要解决2*2规格的。处理的时候要注意向上调整 题目分析:有6*6规格的箱子和一大堆木块 用多少箱子可以把木块都装下 先放大的6*6 5*5 4*4 都需要新开箱子 每4个3*3需要开个新箱子 算下剩多少...

weixin_30721899的博客 365

浅谈专项测试之弱网络测试

浅谈专项测试之弱网络测试 一.弱网络测试背景 移动端产品的使用并非完全都是在流畅的wifi环境,大部分用户主要使用4G,3G,2G等网络,另外因为移动端产品使用的场景多变,如进公交,上地铁,坐电梯,使得弱网测试显得尤为重要。考虑到各种场景的客户端展示及容错,提升产品的印象和用户体验,提高产品的健壮性,弱网测试必不可少。 二.弱网络测试建议 网下需要进行功能点测试,无网络测试,网络切换测试等,测试过程除了关注功能点的实现,还应关注用户体验等各个方面 三.弱网络测试通用功能点总结 四.弱网络测试用例实例

ITstudy001的博客 1010

GPOPSII 对控制量变化率进行约束,避免控制量振荡

在这篇文章中,在GPOPSII中通过对控制量变化的约束,优化求解得到更平滑的控制量曲线,更符合真实控制约束。

Dannyfomer的博客 1870

POJ 1017 Packets 贪心

贪心策略也就是优先放大的,再用小的填剩余的空子。 我们注意到其实那些用来填空子的小格子其实也就只有1x1和2x2这两种,为什么呢?如果我们放6x6的,没有空位子。如果我们用5x5的,我们只能用1x1的来填。如果我们用4x4的,我们可以用2x2,1x1的来填。如果我们用3x3的我们还是可以用1x1,2x2的来填。 这样一想,其实也就是考虑1x1,2x2的格子了。 很简单的就可以得出一个关系。

每天都要进步哦~ 536

【IPC】ONVIF Device Manager 测试工具

介绍onvif 协议测试工具

以实战经验介绍行业知识 1957

POJ1017——Packets(贪心)

题目链接        一道很简单贪心,结果被自己做蠢了。题目要求有6种不同规格的箱子,分别是1*1,2*2,3*3,4*4,5*5,6*6。要对这6种规格的箱子打包,但是包裹的规格只有6*6的。所以问你如何用尽量少的包裹打包,输出包裹数。我的做法就是老老实实的模拟,先装6*6的,每个包裹只能装一个6*6,再装5*5,一个包裹只能装一个5*5和11个1*1,再是4*4。。。就这样一直模拟下去

Jason_crawford的博客 603

2021年03月 C/C++(五级)真题解析#中国电子学会#全国青少年软件编程等级考试

给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0。n的位数为m。现在从m位中删除k位(0

人生就是一个不断学习的过程 1010

Python爬虫实战:基于Playwright与异步技术的专利数据抓取系统

专利数据是企业技术创新、市场竞争分析和行业趋势预测的关键情报来源。然而,专利数据通常分散在各个国家的专利局网站,数据结构复杂,反爬机制严格,使得高效抓取成为技术挑战。本文将详细介绍如何构建一个基于最新Python技术的专利数据抓取系统,涵盖Selenium的现代化替代方案Playwright、异步编程、智能代理轮换等高级技术。

2201_76125261的博客 1562

poj1017——Packets

题目大意:将高度相同的小盒子装入6*6的大盒子中,正方形底面的小盒子有六种型号,底面边长分别为1~6,问最多用几个大盒子输入:六中型号的小盒子的个数         结束:六个0输出:最小大盒子个数分析:贪心法。代码:转载自https://blog.youkuaiyun.com/whuxiaoqiang/article/details/7705380#include &lt;stdlib.h&gt; #inc...

tzyshiwolaogongya的博客 241

多角度模板匹配的模板创建技巧

基于形状的模板匹配多角度创建技巧

manuoo的专栏 3402

POJ 1017 Packets-装格子 (简单贪心)

http://poj.org/problem?id=1017 1.题意: 一个工厂制造的产品形状都是长方体盒子,它们的高度都是 h,长和宽都相等,一共有六个型号,分别为1*1, 2*2, 3*3, 4*4, 5*5, 6*6。 这些产品通常使用一个 6*6*h 的长方体箱子包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的箱子数量BoxNum。

ACM_10000h的专栏 1749

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 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 1017 Packets (贪心算法)

题目链接:poj1017 Packets 题目大意:现在分别有11,22…66的二次元箱子若干,问至少需要几个66的二次元箱子才能装下。 题解:真的想了超级久的题,想着能不能用什么面积相关,长和宽之类的解法,无奈看了题解,结果是用了找规律的办法。贪心策略:优先放入大的箱子,66,55,44的箱子都会直接花一个箱子来装,33的一个箱子可以装四个,看剩下的缝隙能不能塞下剩下的箱子。 #include ...

weixin_44880917的博客 369

廖雪峰Python教程[完整版]

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

贪心问题(POJ1700/1017/1065)(C++)

本文主要就贪心问题给出了讲解和例题的讲述,使用C++语言,基于贪心问题(POJ1700/1017/1065)

CUGLin的博客 1285

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

POJ 1017 Packets

POJ 1017题目大意如下: 有1*1、2*2、3*3、4*4、5*5、6*6这六种型号的包装盒,也指定了相对于这六种型号的产品的分别的数量。由于物流运送费用是和运送商品的数量成正比的(商品运送的时候是包装在包装盒里的),为了节省物流开支,需要确定一种最佳的包装方案,即:使用最少数量的包装盒。 简单的贪心,具体分析如下: 1)都使用6*6的包装盒; 2)如果一个包装盒里包装的是6*6

kornberg_fresnel的博客 381

Poj 1017 Packets【贪心+细节】

Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 49569   Accepted: 16769 Description A factory produces products packed in square packets of the sam

希望的专栏 3601

北大ACM(POJ1017-Packets)

Question:http://poj.org/problem?id=1017 问题点:贪心。 1 Memory: 224K Time: 32MS 2 Language: C++ Result: Accepted 3 4 #include <iostream> 5 using namespace std; 6 ...

aenv6574的博客 257

POJ 1017 Packets(贪心)

题目链接:http://poj.org/problem?id=1017 不解释,贪心思路,可以留言讨论。 #include #include using namespace std; int num[4]= {0,5,3,1}; int main() { int a1,a2,a3,a4,a5,a6,ans1,ans2,ans3,ans4,ans5,ans6; while(~sc

630

张三的包裹厂:C++用贪心算法解POJ1017_Packets问题

POJ1017 Packets 题目链接: POJ1017 Packets 简单理解一下题目: 张三的包裹厂需要将一定数量的盒子放进统一66大小的包裹里打包给客户,所有盒子包括最后的包裹高都为h,也就是说我们只需要考虑横向面积就可以。然后要考虑到不能只按照面积来算,比如66的包裹放了55的盒子之后,66-55=11,尽管33小于11,也放不下,只能放进去1*1的,因为长宽两边都只剩下1宽度的空隙。 简单分析一下题目: 这个题我一开始我的代码一直WA,后来看见Discuss里有个大佬6行就写出来了,属实是让人

只想AC的博客 488

POJ1017 Packets

POJ1017 PacketsDescription 一个工厂制造的产品都是高度为h,长和宽相等的长方体,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6。这些产品通常使用一个6*6*h的长方体包裹包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的包裹数量。

Lxp的博客 608

POJ 1017 Packets (贪心)

Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45720   Accepted: 15454 Description A factory produces products packed in square packets of the sam

TaoSama's Microcosm 481

贪心 —— POJ 1017 Packets

贪心 —— POJ 1017 Packets

大田二十 696

poj 1017 - packets

典型的贪心算法 /*-------------------------------------------------------------------------------------- * FileName:Packets.c * author:doodlesomething@163.com * date:10-28-2014 * version:1.0 * descripti

doodlesomething 768

POJ1017 Packets(贪心)

题意: 有高度相同,底面积为1*1,2*2,3*3……6*6的产品,包裹底面积是6*6的,求最小的包裹数。 要点: 很明显是贪心,思路比较好理清楚,就是优先选大的产品,注意都是向上取整。 15425287 Seasonal 1017 Accepted 164K 16MS C++ 594B 2016-04-22 22:17:47 #inc

SeasonJoe的博客 599
上一篇: oracle用户创建及权限设置
下一篇: POJ 1328 Radar Installation(预处理贪心)
hellohelloC
博客等级 码龄12年 15粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值