搜狐2017校招编程题
2017-08-28 20:58
260 查看
题目1
输出序列题
通过率为100%
题目2
题目描述
工厂生产的包裹在相同高度h,尺寸为 1*1, 2*2, 3*3,4*4,5*5,6*6 的盒子。组装成 6 * 6的大盒子,问最少装几个盒子
输入
输入为几行,每一行代表一个订单,一行6个整数,分别为 1 * 1 至 6 * 6 这6个产品的数量,最后一行输入 6个0.
输出
每个订单输出一行最小包裹数目
代码如下,通过率100%
输出序列题
通过率为100%
#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { int n = 0; int m = 0; while (cin >> n && cin >> m) { if (0 == n || 0 == m) break; vector<int> a(m, 0); for (int i = 0; i < m; i++) { cin >> a[i]; } vector<int > out(n, 0); int tem1 = 0, tem2 = 0; int j = 0; for (int i = 0; i < n; i++) { out[i] = a[tem1]; tem2++; if (tem2 == out[j]) { tem2 = 0; tem1 = (tem1 + 1) % m; j++; } } for (int i = 0; i < out.size(); i++) { printf("%d\n", out[i]); } } return 0; }
题目2
题目描述
工厂生产的包裹在相同高度h,尺寸为 1*1, 2*2, 3*3,4*4,5*5,6*6 的盒子。组装成 6 * 6的大盒子,问最少装几个盒子
输入
输入为几行,每一行代表一个订单,一行6个整数,分别为 1 * 1 至 6 * 6 这6个产品的数量,最后一行输入 6个0.
输出
每个订单输出一行最小包裹数目
代码如下,通过率100%
#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { while (1) { string line; getline(cin, line); stringstream ss(line); vector<int> blocks(6, 0); for (int i = 0; i < 6; i++) { ss >> blocks[i]; } int out = 0; // 6 out += blocks[5]; blocks[5] = 0; // 5 out += blocks[4]; while (blocks[4] > 0 && blocks[0] > 0) { blocks[4]--; blocks[0] = (blocks[0] >= 11) ? (blocks[0] - 11) : 0; } blocks[4] = 0; // 4 out += blocks[3]; while (blocks[3] > 0 && (blocks[0] > 0 || blocks[1] > 0)) { blocks[3]--; if (blocks[1] >= 5) { blocks[1] -= 5; } else if (blocks[1] > 0) { int tmp = 20 - blocks[1] * 4; blocks[0] = (blocks[0] > tmp) ? blocks[0] - tmp : 0; blocks[1] = 0; } else { blocks[0] = (blocks[0] > 20) ? blocks[0] - 20 : 0; } } blocks[3] = 0; // 3 while (blocks[2] >= 4) { out += 1; blocks[2] -= 4; } if (blocks[2] > 0) { out += 1; int tmp = 36 - 9 * blocks[2]; if (blocks[1] > 0) { int tmp1 = tmp / 4 - 1; if (blocks[1] >= tmp1) { blocks[1] -= tmp1; tmp -= tmp1 * 4; } else { tmp -= blocks[1] * 4; blocks[1] = 0; } } if (blocks[0] > 0) { blocks[0] = blocks[0] > tmp ? (blocks[0] - tmp) : 0; } } // 2 while (blocks[1] >= 9) { out += 1; blocks[1] -= 9; } if (blocks[1] > 0) { out += 1; int tmp = 36 - blocks[1] * 4; if (blocks[0] > 0) { blocks[0] = blocks[0] > tmp ? (blocks[0] - tmp) : 0; } } // 1 while (blocks[0] > 36) { out += 1; blocks[0] -= 36; } if (blocks[0] > 0) { out += 1; } if (0 == out) { break; } printf("%d\n", out); } return 0; }
相关文章推荐
- 2017京东校招编程题 烽火台
- 2017京东校招笔试编程题--python
- 搜狐2017 WEB前端开发 秋招笔试编程题
- 携程校招2017编程题之股票最大利润
- 2017华为校招编程题2
- 搜狐2017笔试编程题--Kolakoski序列
- 2017京东校招笔试编程题:进制转换、辗转相除
- 今日头条2017校招编程题
- 2017校招 360 笔试题 编程题 内存管理
- 今日头条2017秋季校招在线编程题解法参考
- 2017网易有道校招三道编程题
- 2017校招去哪网,阿里,网易,中兴,华为笔试编程题五则(Python描述)
- 完美2017校招编程题 小萌的副本生涯
- 360在线编程题2-2017校招服务器端-跳格子
- 牛客网-2017校招编程题
- 搜狐2017笔试编程题
- 微软2017校招编程题 Composition(DP)
- 【编程题】京东校招 2017 集合
- 京东2017校招笔试编程题iOS开发工程师
- 2017校招 美团笔试题 编程题 层次遍历多叉树