https://codeforces.com/contest/902/problem/C

题意:

给你树的深度和树的每个节点的深度,问你是否有重构,如果有重构输出两个不同的结构

题解:

如果相邻节点的深度都大于1的话,这两个节点就是某个节点的子树,所以会有同构,输出子节点在同一个父节点上的情况和子节点不在同一个父节点上的情况即可

代码如下:

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 3e5+;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+;
int h;
int num[maxn]; int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
scanf("%d",&h);
num[]=;
for(int i=;i<=h+;i++)
scanf("%d",&num[i]);
int flag=;
for(int i=;i<=h;i++){
if(num[i]>&&num[i+]>) flag=;
}
if(flag) cout<<"perfect"<<endl;
else{
int now=;
printf("ambiguous\n");
for(int i=;i<=h+;i++){
for(int j=;j<num[i];j++){
printf("%d ",now);
}
now+=num[i];
}
printf("\n");
now=;
for(int i=;i<=h+;i++){
if(num[i]>&&num[i-]>){
for(int j=;j<num[i];j++){
printf("%d ",now);
}
printf("%d ",now-);
}else{
for(int j=;j<num[i];j++){
printf("%d ",now);
} }
now+=num[i];
}
} }

codeforces902C. Hashing Trees的更多相关文章

  1. Codeforces 902C/901A - Hashing Trees

    传送门:http://codeforces.com/contest/902/problem/C 本题是一个关于“树”的问题. 将一棵高度为h的有根树表示为数列{ai|i=0,1,2,...,h},其中 ...

  2. 【Codeforces Round #453 (Div. 2) C】 Hashing Trees

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有当a[i]和a[i-1]都大于1的时候才会有不同的情况. a[i] >= a[i-1] 且a[i-1]>=2 则 ...

  3. Codeforces Round #453 (Div. 1)

    Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出 ...

  4. Codeforces Round #453 ( Div. 2) Editorial ABCD

    A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #453 Div. 2 A B C D (暂时)

    // 从大作业和实验报告中爬出来水一发 // 补题...还是得排在写完实验报告之后... A. Visiting a Friend 题意 给定若干段行车区间,问能否从起点到终点 思路 扫描一遍,维护最 ...

  6. Codeforces Round #453

    Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...

  7. 一致性 hash 算法( consistent hashing )a

    一致性 hash 算法( consistent hashing ) 张亮 consistent hashing 算法早在 1997 年就在论文 Consistent hashing and rando ...

  8. 一致性 hash 算法( consistent hashing )

    consistent hashing 算法早在 1997 年就在论文 Consistent hashing and random trees 中被提出,目前在cache 系统中应用越来越广泛: 1 基 ...

  9. Optimizing shaper — hashing filters (HTB)

    I have a very nice shaper in my linux box :-) How the configurator works — it’s another question, he ...

随机推荐

  1. 005---Python数据类型--字典

    字典 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px ...

  2. Python3爬虫(六) 解析库的使用之Beautiful Soup

    Infi-chu: http://www.cnblogs.com/Infi-chu/ Beautiful Soup 借助网页的结构和属性等特性来解析网页,这样就可以省去复杂的正则表达式的编写. Bea ...

  3. Python自动化运维——系统性能信息模块

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:psutil psutil是一个跨平台库,可以很轻松的为我们实现获取系统运行的进程和资源利用率等信息. 功能 ...

  4. 动态规划(DP)算法

    参考https://blog.csdn.net/libosbo/article/details/80038549 动态规划是求解决策过程最优化的数学方法.利用各个阶段之间的关系,逐个求解,最终求得全局 ...

  5. RAID(冗余硬盘阵列)

    一. RAID定义 RAID( Redundant Array of Independent Disk 独立冗余磁盘阵列 )技术是加州大学伯克利分校1987年提出,最初是为了组合小的廉价磁盘来代替大的 ...

  6. 解析HTML利器AngleSharp介绍

    解析HTML利器AngleSharp介绍 AngleSharp是基于.NET(C#)开发的专门为解析xHTML源码的DLL组件. 项目地址:https://github.com/FlorianRapp ...

  7. 通过修改Host文件解决主机头访问网站的问题

             网站打包发布后,一般都是通过IP地址来进行访问,但是这样不方便记忆.如何设置一个简单的域名,然后通过域名来进行访问呢?一个可行的方法就是修改本机的host文件,添加一条映射关系,把这 ...

  8. npm命令 VS yarn命令

    npm yarn 说明 npm init yarn init  在项目中引导创建一个package.json文件 npm install yarn install/yarn  安装所有依赖包(依据pa ...

  9. Laravel 5.5 创建全局公共函数

    一.需求 我在使用 Laravel 进行项目逻辑处理的时候要加载一些方法,需要全局调用 这个方法又必须得是一个全局函数,因此需要给 Laravel 创建全局的公共函数 二.实现 1.创建文件 在 ap ...

  10. 分布式资源调度--YARN框架

    YARN产生背景 YARN是Hadoop2.x才有的,所以在介绍YARN之前,我们先看一下MapReduce1.x时所存在的问题: 单点故障 节点压力大 不易扩展 MapReduce1.x时的架构如下 ...