packets  

时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
总提交: 27            测试通过: 14

描述

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.

输入

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.

输出

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.

样例输入

  1. 0 0 4 0 0 1
  2. 7 5 1 0 0 0
  3. 0 0 0 0 0 0

样例输出

  1. 2
  2. 1

题目上传者

crq

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. int v[10];
  9. int ava[10];
  10. int cnt = 0;
  11.  
  12. void work() {
  13. cnt = 0;//init
  14. int res;//剩余的
  15. cnt += v[6];//v[6] == 0;
  16. if(v[5]) { //v[5] == 0;
  17. cnt += v[5];
  18. ava[1] += v[5]*11;//ava[1] += 11;!!!
  19. }
  20. if(v[4]) {
  21. cnt += v[4];
  22. ava[2] += v[4] * 5;
  23. }
  24. if(v[3]) {
  25. int tag = true;
  26. cnt += v[3]/4 ;//v[3] < 4; 3*3*4 == 36;
  27. res = v[3]%4; //占用了几个.
  28.  
  29. if(res==0) tag = false;
  30. else cnt++;
  31.  
  32. if(res==1 && tag) {//占用一个3*3
  33. ava[2] += 5;
  34. ava[1] += 7;
  35. tag = false;
  36. }
  37. if(res==2 && tag){//two 3*3
  38. ava[2] += 3;
  39. ava[1] += 6;
  40. tag = false;
  41. }
  42. if(res==3 && tag) {
  43. ava[2] += 1;
  44. ava[1] += 5;
  45. tag = false;
  46. }
  47. }
  48. if(v[2]) {
  49. if(ava[2] >= v[2]) {
  50. ava[1] += (ava[2]-v[2]) * 4;
  51. }
  52. else {
  53. v[2] -= ava[2];
  54. cnt += v[2]/9;//2*2*9 = 36
  55. res = v[2]%9;
  56. if(res != 0) cnt++;
  57. ava[1] += (9-res) * 4;
  58. }
  59. }
  60. if(v[1]) {
  61. if(ava[1]>=v[1]) {
  62. return;
  63. }
  64. else {
  65. v[1] -= ava[1];
  66. cnt += v[1]/36;
  67. res = v[1]%36;
  68. if(res) cnt++;
  69. }
  70. }
  71. return;
  72. }
  73.  
  74. int main()
  75. {
  76. memset(ava, 0, sizeof(ava));
  77. memset(v, 0, sizeof(v));
  78. while(scanf("%d%d%d%d%d%d", &v[1], &v[2], &v[3], &v[4], &v[5], &v[6])==6) {
  79. if(v[0]==v[1] && v[1]==v[2]&&v[2]==v[3]&&v[3]==v[4]&&v[4]==v[5]&&
  80. v[5]==v[6]&&v[6]==0) break;
  81. work();
  82. printf("%d\n", cnt);
  83. memset(ava, 0, sizeof(ava));
  84. memset(v, 0, sizeof(v));
  85. }
  86. return 0;
  87. }

packets的更多相关文章

  1. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

    今天项目中报了如下错误 The last packet sent successfully to the server was 0 milliseconds ago. The driver has n ...

  2. RUDP之二 —— Sending and Receiving Packets

    原文链接 原文:http://gafferongames.com/networking-for-game-programmers/sending-and-receiving-packets/ Send ...

  3. Packets(模拟 POJ1017)

    Packets Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 47750 Accepted: 16182 Description ...

  4. PCI Express(三) - A story of packets, stack and network

    原文出处:http://www.fpga4fun.com/PCI-Express3.html Packetized transactions PCI express is a serial bus. ...

  5. MySQL报错:Packets larger than max_allowed_packet are not allowed 的解决方案

    在导大容量数据特别是CLOB数据时,可能会出现异常:“Packets larger than max_allowed_packet are not allowed”. 这是由于MySQL数据库有一个系 ...

  6. poj 1017 Packets 裸贪心

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43189   Accepted: 14550 Descrip ...

  7. What is martian source / martian packets

    Martian source / Martian packets In Linux, by default, packets are considered individually for routi ...

  8. openstack 控制节点大流量对外发包,nf_conntrack,table full droping packets

    某些人很MJJ,挂了N多代理来疯狂采集,把服务器带宽都耗尽了,没办法只好封掉一些! 目前发现的问题openStack kilo for ubuntu manuual运行一段时间后 云平台的控制节点p5 ...

  9. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. (关于jdbc)

    The last packet sent successfully to the server was milliseconds ago. The driver has not received an ...

随机推荐

  1. struts.xml中的intercepter

    1. http://weizhilizhiwei.iteye.com/blog/1005210 Struts2 的核心——拦截器[Interceptor] 2. http://blog.csdn.ne ...

  2. Sql Server使用技巧

    1.修改表的字段时,提示不能更改: 工具>选项>设计器>取消 阻止保存要求重新创建表的更改 2.更改选择多少行,编辑多少行: 工具>选项>Sql Server对象资源管理 ...

  3. [转]Delphi : keydown与keypress的区别,组合键

    Shift 是一个集合变量. type TShiftState = set of (ssShift, ssAlt, ssCtrl, ssLeft, ssRight, ssMiddle, ssDoubl ...

  4. (转)C#Interface简介

    接口:描述可属于任何类或结构的一组相关功能,通过interface关键字来声明:接口只包含方法.委托或事件和属性的签名(接口包含的成员).不能包含字段(因为字段是包含数据的).方法的实现是“继承”接口 ...

  5. MFC框架类、文档类、视图类相互访问的方法

    1.获取应用程序指针 CMyApp* pApp=(CMyApp*)AfxGetApp(); 2.获取主框架指针 CWinApp 中的公有成员变量 m_pMainWnd 就是主框架的指针 CMainFr ...

  6. [LeetCode OJ] Candy

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  7. createElement()结合appendChild()的实例

    createElement()作用是在JavaScript中创建一个元素 appendChild()向html元素添加节点 下面是冲浪后改编的例子代码 先插html代码 <body> &l ...

  8. Linux(Debian)上安装Redis教程

    -- 第一步下载文件到该目录 cd /usr/local/src wget http:.tar.gz 解压 tar xzf redis.tar.gz -- 第二步编译安装 make make all ...

  9. (转)ligerUI 使用教程之Tip介绍与使用

    概述:   ligertip是ligerUI系列插件中的tooltip类插件,作用是弹一个浮动层,起提示作用   阅读本文要求具备jQuery的基本知识,不然文中的javascript代码不易理解 截 ...

  10. 字符串处理——strpos()函数

    strpos() 函数返回字符串在另一个字符串中第一次出现的位置. 大小写敏感 如果没有找到该字符串,则返回 false. strpos(string,find,start)  string 必需:规 ...