标签:不同的 space ++ ffffff 结构体 种类 个数 思路 res
结构体记录每三个数可以形成的砖块,以长宽排序,从小到大遍历,将每个砖块上面能垒上去的高度叠加。
因为从小往大,之前的砖块都是能垒的最大高度。
#include <iostream> #include <memory.h> #include <string> #include <istream> #include <sstream> #include <vector> #include <stack> #include <algorithm> #include <map> #include <queue> #include <math.h> #include <cstdio> using namespace std; typedef long long LL; const int MAXN = 30 * 6 + 10; const int INF = 0x7fffffff; struct Node { int _x, _y; int _h; bool operator < (const Node & that) const { if (this->_x != that._x) return this->_x < that._x; return this->_y < that._y; } }node[MAXN]; int main() { int n; int a, b, c; int cnt = 1; while (cin >> n && n) { int pos = 0; for (int i = 1;i <= n;i++) { cin >> a >> b >> c; pos++, node[pos]._x = a, node[pos]._y = b, node[pos]._h = c; pos++, node[pos]._x = a, node[pos]._y = c, node[pos]._h = b; pos++, node[pos]._x = b, node[pos]._y = a, node[pos]._h = c; pos++, node[pos]._x = b, node[pos]._y = c, node[pos]._h = a; pos++, node[pos]._x = c, node[pos]._y = a, node[pos]._h = b; pos++, node[pos]._x = c, node[pos]._y = b, node[pos]._h = a; } sort(node + 1, node + 1 + pos); int res = node[1]._h; for (int i = 1;i <= pos;i++) { int tmp = 0; for (int j = 1;j < i;j++) { if (node[j]._x < node[i]._x && node[j]._y < node[i]._y) tmp = max(tmp, node[j]._h); } node[i]._h += tmp; res = max(res, node[i]._h); } printf("Case %d: maximum height = %d\n", cnt++, res); } return 0; }
标签:不同的 space ++ ffffff 结构体 种类 个数 思路 res
原文地址:https://www.cnblogs.com/YDDDD/p/10354927.html