博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-1069-Monkey and Banana
阅读量:7015 次
发布时间:2019-06-28

本文共 1792 字,大约阅读时间需要 5 分钟。

链接:https://vjudge.net/problem/HDU-1069#author=prayerhgq

题意:

一组研究人员正在设计一项实验,以测试猴子的智商。他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子。如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉。
 
研究人员有n种类型的砖块,每种类型的砖块都有无限个。第i块砖块的长宽高分别用xi,yi,zi来表示。 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高。
 
在构建塔时,当且仅当A砖块的长和宽都分别小于B砖块的长和宽时,A砖块才能放到B砖块的上面,因为必须留有一些空间让猴子来踩。
 
你的任务是编写一个程序,计算猴子们最高可以堆出的砖块们的高度。

思路:

结构体记录每三个数可以形成的砖块,以长宽排序,从小到大遍历,将每个砖块上面能垒上去的高度叠加。

因为从小往大,之前的砖块都是能垒的最大高度。

代码:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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;}

  

转载于:https://www.cnblogs.com/YDDDD/p/10354927.html

你可能感兴趣的文章
CentOS VMware 下SSH配置方法详解
查看>>
PHP错误级别 error_reporting() 函数详解
查看>>
为网卡配置多个IP地址(windows)
查看>>
WIndows 使用VS编译 Lua5
查看>>
转 VB ListView控件各种操作详解
查看>>
MinGW32和64位交叉编译环境的安装和使用
查看>>
什么是“单播”“组播”和“多播”
查看>>
flex---->图表控件
查看>>
分析函数调用关系图(call graph)的几种方法
查看>>
11.0592M晶振与12M晶振
查看>>
A380上11万一张的机票什么享受?来看看
查看>>
LeetCode: 103_Binary Tree Zigzag Level Order Traversal | 二叉树Zigzag层次遍历 | Medium
查看>>
JUnit单元测试中的setUpBeforeClass()、tearDownAfterClass()、setUp()、tearDown()方法小结
查看>>
ubuntu15.10下编译安装wine1.8 rc4
查看>>
jquery获取节点的时候获取包含自己在内的HTML标签
查看>>
CPU profiling
查看>>
Exchanging Partitions and Subpartitions with Tables--官方文档
查看>>
[Typescript] Typescript Enums vs Booleans when Handling State
查看>>
Java中HashMap源码分析
查看>>
(转)c#.net常用字符串函数
查看>>