Zoj 1093 Monkey and Banana

此算法问题探讨了如何通过堆叠不同尺寸的积木帮助猴子拿到高处的香蕉。需要考虑积木放置的限制条件,使用贪心算法找到能达到的最大高度。
Monkey and Banana

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

The researchers have n types of blocks, and an unlimited supply ofblocks of each type. Each type-i block was a rectangular solid withlinear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the otherdimension was the height.

They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placedon top of another block as long as the two base dimensions of theupper block were both strictly smaller than the corresponding basedimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized basescouldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.

Input Specification

The input file will contain one or more test cases. The first line of each test case containsan integer n,
representing the number of different blocks in the following data set.The maximum value for n is 30.
Each of the next n lines contains three integersrepresenting the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.

Output Specification

For each test case, print one line containing the case number(they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format"Case case: maximum height = height"

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342

贪心?。

排序之后对于当前每次能达到的最大高度是在它之前的满足要求下(长和宽都小于当前积木)的最大高度加上自己的高度。


#include<cstdio>
#include<algorithm>

using namespace std;

struct Node{
    long long x,y;
    long long w,s;
}num[300];

bool cmp1(Node a,Node b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;
}

int main()
{
    long long n;
    long long i,j;
    long long count,t=1,tmp;

    while(scanf("%lld",&n),n)
    {
        count=0;
        for(i=1;i<=n;i++)
        {
            count++;
            scanf("%lld%lld%lld",&num[count].x,&num[count].y,&num[count].w);
	    num[++count].x=num[count-1].y;  num[count].y=num[count-1].x;  num[count].w=num[count-1].w;
            num[++count].x=num[count-2].w;  num[count].y=num[count-2].x;  num[count].w=num[count-2].y;
	    num[++count].x=num[count-3].x;  num[count].y=num[count-3].w;  num[count].w=num[count-3].y;
	    num[++count].x=num[count-4].y;  num[count].y=num[count-4].w;  num[count].w=num[count-4].x;
	    num[++count].x=num[count-5].w;  num[count].y=num[count-5].y;  num[count].w=num[count-5].x;
        }  

	sort(num+1,num+1+count,cmp1);
        for(i=1;i<=count;i++)
            num[i].s=num[i].w;
        long long max;
        for(i=1;i<=count;i++)
        {
            max=0;
            for(j=1;j<i;j++)
            {
                if(num[i].x>num[j].x && num[i].y>num[j].y && num[j].s>max)
                    max=num[j].s;
            }
            num[i].s=num[i].w+max;
        }

        max=0;
        for(i=1;i<=count;i++)
            if(num[i].s>max)
                max=num[i].s;
        printf("Case %lld: maximum height = %lld\n",t++,max);
    }
    return 0;
}


 


                
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!
内容概要:本文系统介绍了基于最小势能原理(即能量法)的物理信息神经网络(PINNs)在求解固体力学二维问题中的理论框架与应用实践,并提供了完整的PyTorch代码实现案例。该方法通过将物理系统的总势能泛函嵌入神经网络的损失函数中,利用深度学习框架直接求解满足控制方程和边界条件的位移场近似解,避免了传统数值方法对网格划分的依赖。文章重点剖析了基于变分原理的能量形式如何替代强形式偏微分方程构建损失项,提升了求解的稳定性与泛化能力。同时,研究对比了不同PINNs架构与训练策略在处理复杂几何形状、非均匀材料属性及非线性力学行为时的精度、收敛性与计算效率,验证了其在处理经典弹性力学问题(如平面应力/应变问题)中的有效性与潜力。配套代码便于读者复现结果并拓展至更广泛的工程应用场景。; 适合人群:具备一定深度学习基础和固体力学知识的研究生、科研人员及工程技术从业者,特别适用于从事计算力学、智能仿真、物理驱动建模、结构分析等方向的研究者。; 使用场景及目标:①掌握基于能量法的PINNs建模范式,理解其相较于传统有限元法的优势与局限;②研究物理信息神经网络在无网格求解复杂边界与非线性问题中的能力;③对比不同神经网络结构对求解精度与收敛速度的影响,推动PINNs在工程实际中的落地应用。; 阅读建议:建议读者结合所提供的PyTorch代码逐模块分析网络构建、能量泛函定义、边界条件施加及训练流程设计,深入理解物理约束与机器学习模型的融合机制,并鼓励在自定义问题中调整网络参数、采样策略与损失权重以优化性能。
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值