codeforces902C. Hashing Trees
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的更多相关文章
- Codeforces 902C/901A - Hashing Trees
传送门:http://codeforces.com/contest/902/problem/C 本题是一个关于“树”的问题. 将一棵高度为h的有根树表示为数列{ai|i=0,1,2,...,h},其中 ...
- 【Codeforces Round #453 (Div. 2) C】 Hashing Trees
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有当a[i]和a[i-1]都大于1的时候才会有不同的情况. a[i] >= a[i-1] 且a[i-1]>=2 则 ...
- Codeforces Round #453 (Div. 1)
Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出 ...
- 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 ...
- Codeforces Round #453 Div. 2 A B C D (暂时)
// 从大作业和实验报告中爬出来水一发 // 补题...还是得排在写完实验报告之后... A. Visiting a Friend 题意 给定若干段行车区间,问能否从起点到终点 思路 扫描一遍,维护最 ...
- Codeforces Round #453
Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...
- 一致性 hash 算法( consistent hashing )a
一致性 hash 算法( consistent hashing ) 张亮 consistent hashing 算法早在 1997 年就在论文 Consistent hashing and rando ...
- 一致性 hash 算法( consistent hashing )
consistent hashing 算法早在 1997 年就在论文 Consistent hashing and random trees 中被提出,目前在cache 系统中应用越来越广泛: 1 基 ...
- Optimizing shaper — hashing filters (HTB)
I have a very nice shaper in my linux box :-) How the configurator works — it’s another question, he ...
随机推荐
- atlas+mysql部署mysql读写分离
1.atlas 简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基 ...
- python2.7入门---SMTP发送邮件
SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.python的smtplib提 ...
- HTC Vive小场地与大场景空间的解决方案
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52780621 作者:car ...
- MySQL数据库性能优化专题
摘录: 书:<MySQL性能调优与架构设计> 一个系列: (按顺序排一下) MySQL 数据库性能优化之缓存参数优化 http://isky000.com/database/mysql-p ...
- CS229 1
1.机器学习 机器学习是工具,具体应用到某个实际场景下,才是目的. 2.分类 a 监督学习,包括回归(regression),分类(classification).回归问题,数据可以是连续或者离散,分 ...
- lua优化
前言 Lua是一门以其性能著称的脚本语言,被广泛应用在很多方面,尤其是游戏.像<魔兽世界>的插件,手机游戏<大掌门><神曲><迷失之地>等都是用Lua来 ...
- Linux系统安装jdk后出现无法执行binary 文件的错误解决
这是由于jdk版本的问题,针对Linux系统,Oracle提供了 ARM 的32jdk和64位jdk , 但是也提供了类似这样jdk-8u191-linux-i586.tar.gz32或64位的jdk ...
- window平台下使用python虚拟环境
第一步:安装virtualenv模块 安装virtualenv模块,使用pip install C:\Users\wangjun>pip install virtualenv 第二步:创建虚拟环 ...
- cpp语言程序设计教程第七章的一道编程题
题目如下 按下列要求实现一个有关学生成绩的操作. 该类名为Student. (1)每个学生的信息包含有姓名(字符数组)和成绩(int型). (2)共有5个学生,用对象数组表示. (3)计算出5个学生中 ...
- Ubuntu18.04 + CUDA9.0 + cuDNN7.3 + Tensorflow-gpu-1.12 + Jupyter Notebook深度学习环境配置
目录 一.Ubuntu18.04 LTS系统的安装 1. 安装文件下载 2. 制作U盘安装镜像文件 3. 开始安装 二.设置软件源的国内镜像 1. 设置方法 2.关于ubuntu镜像的小知识 三.Nv ...