Prototypes analyze

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述

ALpha 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.

 
输入
The first line of the input contains one integers T, which is the nember of test cases (1<=T<=8). Each test case specifies: * Line 1: 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.
输出
For each test case generate a single line containing a single integer that is the number of different tree shapes.
样例输入
1
5 3
2 7 1
1 5 9
3 1 4
2 6 5
9 7 3
样例输出
4
来源
河南省第九届省赛
题解:其实也挺水的,赛场上一直用的深度左右树来存的数形,其实只要把树存起来不就好了。。。当时脑子抽住了。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
using namespace std; typedef struct Node{
Node *l, *r;
int v;
}Node, *Tree; void build(Tree &p, int v){
if(p == NULL){
p = new Node();
p->v = v;
p->l = p->r = NULL;
return ;
}
if(v < p->v){
build(p->l, v);
}
else if(v > p->v){
build(p->r, v);
}
}
Tree tree[];
void visit(Tree p){ if(p->l){
visit(p->l);
}
if(p->r){
visit(p->r);
}
}
bool jud;
bool judge(Tree a, Tree b){
if(a == NULL && b == NULL)return true;
else if(a && b){
judge(a->l, b->l);
judge(a->r, b->r);
}
else
jud = false;
}
int main(){
int T, n, k;
scanf("%d", &T);
string s[];
while(T--){
int v;
scanf("%d%d", &n, &k);
for(int i = ; i < n; i++){
Tree p = NULL;
for(int j = ; j < k; j++){
scanf("%d", &v);
build(p, v);
}
tree[i] = p;
}
int ans = ;
for(int i = ; i < n; i++){
int flot = ;
for(int j = i + ; j < n; j++){
jud = true;
judge(tree[i], tree[j]);
if(jud){
flot = ;
break;
}
}
ans += flot;
}
printf("%d\n", ans);
}
return ;
}

Prototypes analyze(二叉排序树,不同树形个数)的更多相关文章

  1. nyoj 1278G: Prototypes analyze 与 二叉排序树(BST)模板

    参考博客:https://blog.csdn.net/stpeace/article/details/9067029 参考博客:https://blog.csdn.net/baidu_35643793 ...

  2. 二叉树—-1(No.9HN省赛小题)

    题目: 1013: Prototypes analyze 时间限制: 1 Sec  内存限制: 128 MB提交: 6  解决: 4[提交][状态][讨论版] 题目描述 ALpha Ceiling M ...

  3. 每天一套题打卡|河南省第九届ACM/ICPC

    A 表达式求值 表达式求值:可以用递归求解,也可以用栈模拟,考过多次. 类似题目:NYOJ305,NYOJ35 用栈模拟做法: #include <stdio.h> #include &l ...

  4. 记忆化搜索 codevs 2241 排序二叉树

    codevs 2241 排序二叉树 ★   输入文件:bstree.in   输出文件:bstree.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 一个边长为n的正三 ...

  5. 算法设计与分析 - 李春葆 - 第二版 - html v2

    1 .1 第 1 章─概论   1.1.1 练习题   1 . 下列关于算法的说法中正确的有( ).   Ⅰ Ⅱ Ⅲ Ⅳ .求解某一类问题的算法是唯一的   .算法必须在有限步操作之后停止   .算法 ...

  6. nyoj-1278-Prototypes analyze(二叉排序树模板)

    题目链接 思路:建树之后,判断有多少种不同的树. 判断不同的树,简单的思路是遍历数组,判断数组后面是否存在一样的树 /* Name:NYOJ-1278-Prototypes analyze Copyr ...

  7. UVALive-8072 Keeping On Track 树形dp 联通块之间缺失边的个数

    题目链接:https://cn.vjudge.net/problem/UVALive-8072 题意 给出n+1个点和n条边,每对点之间只能存在一条边. 现在要找出一个节点,使得去掉这个点后,所剩每对 ...

  8. 012-数据结构-树形结构-哈希树[hashtree]、字典树[trietree]、后缀树

    一.哈希树概述 1.1..其他树背景 二叉排序树,平衡二叉树,红黑树等二叉排序树.在大数据量时树高很深,我们不断向下找寻值时会比较很多次.二叉排序树自身是有顺序结构的,每个结点除最小结点和最大结点外都 ...

  9. 【数据结构】简单谈一谈二分法和二叉排序树BST查找的比较

    二分法查找: 『在有序数组的基础上通过折半方法不断缩小查找范围,直至命中或者查询失败.』   二分法的存储要求:要求顺序存储,以便于根据下标随机访问   二分法的时间效率:O(Log(n))   二分 ...

随机推荐

  1. webService返回自定义类型的数据处理

    1.自定义一个Student 数据类型: package com.chnic.webservice; import java.io.Serializable; public class Student ...

  2. 一个不错的PPT,扁平化设计,开放资源,要的进来

    开了那么多的博客,没做啥资源贡献,今天共享一个不错的PPT模板.例如以下图所看到的,须要的话留下邮箱 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFp ...

  3. git的0基础使用

    1.申请一个git帐号 2.项目开发者将你增加这个项目 3.在终端随意一个目录克隆 该项目地址 git clone 该项目地址 4.进nginx配置 5.更新的时候进入项目目录 git pull

  4. Android 高仿微信头像截取 打造不一样的自定义控件

    转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/39761281,本文出自:[张鸿洋的博客] 1.概述 前面已经写了关于检测手势识别 ...

  5. GridControl 设置焦点单元格

    gdvNew.Focus(); //GridControl 控件获取焦点 gdvNew.FocusedRowHandle = _smtReport.Count - 1; //设置焦点行 gdvNew. ...

  6. 安装软件配置VC++环境时常出现的问题--Error 1935.安装程序集

    装很多软件是都要配置VC++环境的,但由于系统注册表限制,很多时候软件安装过程中会报如下错误 安装 vc++2005 运行库 Error 1935.安装程序集 Microsoft.vc80.atl,t ...

  7. Masters of Doom

    http://blog.codinghorror.com/you-dont-need-millions-of-dollars/ "In the information age, the ba ...

  8. Java数据输入

    以下是数据输入实例: //以下是数据输入实例 import java.util.Scanner;//导入java.util.Scanner,Scanner首字母大写 public class Test ...

  9. ORA-00257: archiver error. Connect internal only, until freed 错误的处理方法

    转帖:原文地址http://blog.csdn.net/panys/article/details/3838846 archive log 日志已满ORA-00257: archiver error. ...

  10. C++11 lambda表达式学习

    lambda表达式是函数式编程的基础.咱对于函数式编程也没有足够的理解,因此这里不敢胡言乱语,有兴趣的可以自己查找相关资料看下.这里只是介绍C++11中的lambda表达式自己的认识.这里有参考文档h ...