【BZOJ】4610 [Wf2016] Ceiling Function

本文探讨了一种新型天花板的设计——IncrediblyCollapse-ProofCeilings (ICPC),通过对不同层数及其抗塌陷能力进行二叉查找树分析,以评估其整体结构稳定性。文章介绍了具体的分析方法及实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description
Advanced Ceiling Manufacturers (ACM) is analyzing the properties of its new series of Incredibly Collapse-Proof Ceilings (ICPCs). An ICPC consists of n layers of material, each with a different value of collapse resistance (measured as a positive integer). The analysis ACM wants to run will take the collapse-resistance values of the layers, store them in a binary search tree, and check whether the shape of this tree in any way correlates with the quality of the whole construction. Because, well, why should it not? To be precise, ACM takes the collapse-resistance values for the layers, ordered from the top layer to the bottom layer, and inserts them one-by-one into a tree. The rules for inserting a value v are:

• If the tree is empty, make v the root of the tree.
• If the tree is not empty, compare v with the root of the tree. If v is smaller, insert v into the left subtree of the root, otherwise insert v into the right subtree.

ACM has a set of ceiling prototypes it wants to analyze by trying to collapse them. It wants to take each group of ceiling prototypes that have trees of the same shape and analyze them together. For example, assume ACM is considering five ceiling prototypes with three layers each, as described by Sample Input 1 and shown in Figure C.1. Notice that the first prototype’s top layer has collapseresistance value 2, the middle layer has value 7, and the bottom layer has value 1. The second prototype has layers with collapse-resistance values of 3, 1, and 4 – and yet these two prototypes induce the same tree shape, so ACM will analyze them together.

Given a set of prototypes, your task is to determine how many different tree shapes they induce.

Input
The first line of the input contains two integers n (1 ≤ n ≤ 50), which is the number of ceiling prototypes to analyze, and k (1 ≤ k ≤ 20), which is the number of layers in each of the prototypes.
The next n lines describe the ceiling prototypes. Each of these lines contains k distinct integers (between 1 and 106, inclusive), which are the collapse-resistance values of the layers in a ceiling prototype, ordered from top to bottom.

Output
Display the number of different tree shapes.

Solution
这题BZ的翻译比较迷幻。这不是个堆,是个二叉查找树。然后这个数据范围我们就把树暴力出来比较即可。
树的生成方式也已经给出(然而我把等于的情况也扔左儿子了,但并不影响……)

#include<stdio.h>
#include<cstring>

int s1l[21],s1r[21],s2l[21],s2r[21],a[51][21],n,m,ans;
bool flag,f[51];

void dfs(const int &now1,const int &now2)
{
    if ((bool)now1 ^ (bool)now2) flag=0;
    if (!flag) return;
    if (s1l[now1]) dfs(s1l[now1],s2l[now2]);
    if (s1r[now1]) dfs(s1r[now1],s2r[now2]);
}

inline void judge(const int &u,const int &v)
{
    s1l[0]=0;s1r[0]=0;int now,last;
    memset(s1l,0,sizeof(s1l));
    memset(s2l,0,sizeof(s2l));
    memset(s1r,0,sizeof(s1r));
    memset(s2r,0,sizeof(s2r));
    for (int i=2;i<=m;i++)
    {
        for (last=0,now=1;now;last=now,now=(a[u][i]<=a[u][now])?s1l[now]:s1r[now]);
        if (a[u][i]<=a[u][last]) s1l[last]=i;
        else s1r[last]=i;
    }
    s2l[0]=0;s2r[0]=0;
    for (int i=2;i<=m;i++)
    {
        for (last=0,now=1;now;last=now,now=(a[v][i]<=a[v][now])?s2l[now]:s2r[now]);
        if (a[v][i]<=a[v][last]) s2l[last]=i;
        else s2r[last]=i;
    }
    flag=1;
    dfs(1,1);
    if (flag) f[v]=1,ans--;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%d",&a[i][j]);
    for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (!f[i] && !f[j]) judge(i,j);
    printf("%d",ans+n);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值