今天是打卡第一台咧,我是有好好想过努力成为大师的。其实是在读那本poj上面的书,最近还在找例题做,话不多说1017上题。

POJ 1017 Packets

[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的箱子装,看看剩余多少的2×2和1×1的箱子。

需要注意的地方就是3×3箱子的情况,因为他们不可以装进去4×4,5×5,6×6装过的箱子里面所以必须要新开一个箱子。然后分四种情况:

1.箱子里只有一个3×3:可以装下5个2×2和7个1×1

2.箱子里有两个3×3:可以装下3个2×2和6个1×1

3.箱子里有三个3×3:可以装下1个2×2和5个1×1

4.箱子里有四个3×3:没空位置了

只要算好了一层一层地填空位就可以了。还有一个点就是,2×2以及1×1的空位够不够,不够的话要开新箱子。

嗯,其实都是学习得来的,自己摸鱼去了。

代码

#include<stdio.h>int main(){int N,a,b,c,d,e,f;//N: total #of casesint x,y; //x: #of 1*1; y: #of 2*2int u[4]={0,5,3,1};while(1){N=0;scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0) break;N=f+e+d+(c+3)/4;//(c+3)/4 trick: ceiling of c/4y=d*5+u[c%4];if(b>y) N+=(b-y+8)/9;//Use subtraction to calculate the remaining 1*1x=36*N-36*f-25*e-16*d-9*c-4*b;if(a>x) N+=(a-x+35)/36;printf("%d\n",N);}return 0;
}

明天再加油咯!

POJ | 1017装箱问题 摸鱼题解相关推荐

  1. POJ 1017 Packets【贪心】

    POJ 1017 题意: 一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为 1*1, 2*2, 3*3, 4*4, 5*5, 6*6.  这些产品通常 ...

  2. 【牛客 - 318E】爱摸鱼的Dillonh(数学,暴力,细节)

    题干: "我不做人啦,jojo!" "Dillonh起来回答问题!" "啊?"沉迷于jojo的Dillonh又一次上课摸鱼被老师抓到了,他慌 ...

  3. iOS摸鱼周报 第二期

    主题列表:juejin, github, smartblue, cyanosis, channing-cyan, fancy, hydrogen, condensed-night-purple, gr ...

  4. 【转】让Chrome化身成为摸鱼神器,利用Chorme运行布卡漫画以及其他安卓APK应用教程...

    下周就是十一了,无论是学生党还是工作党,大家的大概都会有点心不在焉,为了让大家更好的心不在焉,更好的在十一前最后一周愉快的摸鱼,今天就写一个如何让Chrome(google浏览器)运行安卓APK应用的 ...

  5. 上班摸鱼,刚刚发现在 VScode 中可玩魂斗罗,超级玛丽

    今天,再给大家介绍一款更加有意思的vscode插件--"小霸王". GitHub传送门:https://github.com/gamedilong/anes-repository ...

  6. AI 监视打工人,这个国家明确说:保护我方“摸鱼权”!

    ‍‍ 撰文 | 刘芳 来源 | 学术头条 近日,国美控股集团对员工"摸鱼" 的处罚引起了关于职场中隐私权的巨大争议. 事实上,这一事件并非个例.如今人工智能(AI)算法在职场中的使 ...

  7. 「摸鱼」神器来了,Python 实现人脸监测制作神器

    作者 | 李秋键 出品 | AI科技大本营(ID:rgznai100) 最近都在讨论工作摸鱼,网易云音乐也出了合理摸鱼时间表,今天给大家推荐如何用python实现摸鱼~码住呦! 引言:脸部表情是人类情 ...

  8. 技术“摸鱼” 大神,国外小哥 5 年白拿 45 万工资!

    整理 | 孙胜 出品 | CSDN(ID:CSDNnews) 自从2017年谷歌旗下的AlphaGo以3比0战胜柯洁后,"人工智能即将取代人类工作"一度成为人们热议的话题.然而最近 ...

  9. 马斯克公开支持“上班摸鱼”:让工作更愉快!

    整理 | 王晓曼 出品 | 程序人生 (ID:coder _life) 11月16日,在国美集团批评员工上班摸鱼的通报中,一名员工在网易云音乐上使用了22.5G的流量格外显眼.11月18日,网易云音乐 ...

最新文章

  1. python字符串写入excel-Python向excel中写入数据的方法
  2. 英特尔AIDC秀肌肉:展示AI软硬件+生态全景图
  3. java葵花宝典_JAVA程序员想入职跳槽,这些基本功一定要做好,你给自己打几分?...
  4. poj3683 Priest John's Busiest Day
  5. 非对称加解密交互故事
  6. 4.openstack之mitaka搭建glance镜像服务
  7. Pytorch采坑记录:DDP加载之前的checkpoint后loss上升(metric下降)
  8. php网站服务器500,php服务器错误500
  9. H G W S哪一个不是状态函数_HAWE哈威BVH11H/M/S/2-X24换向阀
  10. 简单工厂(Simple Factory)模式
  11. 夜猫专业黑帽seo优化服务团队
  12. c++ STL之unordered_map
  13. 用tomcat6修改java内存_Tomcat 服务器内存修改
  14. VS2017插件工具-VisualSVN(6.3.0)-破解之法
  15. android刷机工具 原理,Android 设备刷机教程
  16. 2016.8.14安装myplayer心得
  17. SAP 银行主数据 SWIFT 码
  18. python从excel中读取数据 写入word_Java调用python脚本,读取excel表格数据并写入word文档-Go语言中文社区...
  19. linux分析mirna,利用DIANA Tools进行miRNA分析
  20. 不必急于吹响裁判哨:“安卓禁令”后华为手机的变数与新机

热门文章

  1. 识别文字什么软件?这几个实用的文字识别软件值得收藏
  2. Windows10 自带壁纸
  3. python监控服务器cpu温度实例_监控HP服务器CPU温度的脚本
  4. 一时兴起之matlab学习记录
  5. 中国隧道掘进机(TBM)行业需求状况与投资价值评估报告2022-2027年
  6. Proteus常见问题
  7. Gradle配置全局变量
  8. 生物信息学笔记02 -- 研究的一般方法
  9. 数据备份失败的五个原因及解决办法
  10. 【笔试】操作系统知识点整理