POJ-1017 Packets
来源:互联网 发布:unity3d寻路算法 编辑:程序博客网 时间:2024/04/26 08:44
题目大意:有货物若干,大小分别为1*1,2*2,3*3,4*4,5*5,6*6,将货物装在6*6大小的箱子中,求最少的箱子个数。
题目链接:http://poj.org/problem?id=1017
简单贪心,从大货物开始考虑即可。
#include <stdio.h>#include <math.h>#include <string.h>int x[7];bool end;int main(){ while (1) { end = true; for (int i = 1; i <= 6; i++) { scanf("%d",&x[i]); if (x[i] != 0) { end = false; } } if (end) break; int pNum=0; int tNum = 0; pNum = x[6]; x[6] = 0; tNum += pNum; pNum = x[5]; x[5] = 0; if (pNum * 11 > x[1]) x[1] = 0; else x[1] = x[1] - pNum * 11; tNum += pNum; pNum = x[4]; x[4] = 0; if (pNum * 5 > x[2]) { if ((pNum * 5 - x[2]) * 4 > x[1]) x[1] = 0; else x[1] = x[1] - (pNum * 5 - x[2]) * 4; x[2] = 0; } else { x[2] = x[2] - pNum * 5; } tNum += pNum; pNum = x[3] / 4; if (x[3] % 4 != 0) { pNum++; if ((4 - x[3] % 4) * 2 - 1 > x[2]) { if (3 * 3 * (4 - x[3] % 4) - 2 * 2 * x[2] > x[1]) x[1] = 0; else x[1] = x[1] - (3 * 3 * (4 - x[3] % 4) - 2 * 2 * x[2]); x[2] = 0; } else { if (3 * 3 * (4 - x[3] % 4) - 2 * 2 * ((4 - x[3] % 4) * 2 - 1) > x[1]) x[1] = 0; else x[1] = x[1] - (3 * 3 * (4 - x[3] % 4) - 2 * 2 * ((4 - x[3] % 4) * 2 - 1)); x[2] = x[2] - ((4 - x[3] % 4) * 2 - 1); } } x[3] = 0; tNum += pNum; pNum = x[2] / 9; if (x[2] % 9 != 0) { pNum++; if ((9 - x[2] % 9) * 4 > x[1]) x[1] = 0; else x[1] = x[1] - (9 - x[2] % 9) * 4; } x[2] = 0; tNum += pNum; pNum = x[1] / 36; if (x[1] % 36 != 0) { pNum++; } x[1] = 0; tNum += pNum; printf("%d\n",tNum); } return 0;}
0 0
- poj 1017 Packets【贪心】
- POJ 1017 Packets(贪心)
- poj 1017 Packets
- POJ 1017 Packets
- POJ 1017 Packets
- poj 1017 Packets(贪心)
- poj 1017 Packets
- poj 1017 Packets
- POJ 1017 Packets
- POJ 1017 Packets
- POJ 1017 Packets
- poj 1017 Packets
- POJ-1017-Packets
- poj 1017 Packets ( 贪心 )
- POJ 1017Packets(贪心)
- POJ 1017 Packets
- poj 1017 Packets
- [POJ][1017]Packets
- leetcode 155: Min Stack
- 计算机视觉牛人博客和代码汇总(全)
- 设计模式之原型模式
- 算法与数据结构学习资料及面试
- 深度学习 vs. 概率图模型 vs. 逻辑学
- POJ-1017 Packets
- Git指令整理
- 相机定位(1)
- Ubuntu 12.04.1 内核编译整个过程(内核2.6.32.70)
- 如何让自己的web应用支持iOS表情
- QT基本数据类型
- css animation 兼容360浏览器
- 让web应用正常显示ios输入法表情
- poj 3225 Help with Intervals 线段树lazy-tag求解区间运算