【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

显然只有当a[i]和a[i-1]都大于1的时候才会有不同的情况。
a[i] >= a[i-1] 且a[i-1]>=2
则第i-1层的a[i-1]个节点,每个节点下面接一个第i层的节点.
然后剩下的a[i]-a[i-1]个都放在第i-1层最左边那个节点下面。
另外一颗树,所有节点都放在第i-1层最左边那颗下面。
如果a[i]2且a[i]>=2
同样的,在第i-1层的前a[i]个节点下面各接一个节点。
然后另外一棵树,第i-1层只在最左边那个节点接

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 1e5; int a[N+50],h;
vector <int> tree[2]; void GetTrees(int idx){
tree[0].push_back(0);
tree[1].push_back(0);
int pre1 = 1,pre2 = -1,now = 1;
for (int i = 2;i <= idx-1;i++){
for (int j = 1;j <= a[i];j++){
tree[0].push_back(pre1);
tree[1].push_back(pre1);
} int cnt = 0;
for (int j = 1;j <= a[i];j++){
now++;cnt++;
if (cnt==1) pre1 = now;
if (cnt==2) pre2 = now;
}
} for (int i = 1;i <= a[idx];i++){
if (i&1) {
tree[0].push_back(pre1);
}else tree[0].push_back(pre2);
tree[1].push_back(pre1);
} for (int i = 1;i <= a[idx];i++){
now++;
pre1 = now;
} for (int i = idx+1;i <= h;i++){
for (int j = 1;j <= a[i];j++){
tree[0].push_back(pre1);
tree[1].push_back(pre1);
}
for (int j = 1;j <= a[i];j++){
now++;
pre1 = now;
}
}
for (int x:tree[0]){
cout << x <<' ';
}
cout << endl;
for (int x:tree[1]){
cout << x <<' ';
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> h;h++;
for (int i = 1;i <= h;i++) cin >> a[i];
for (int i = 2;i <= h;i++)
if (a[i]>=2 && a[i-1]>=2){
cout << "ambiguous" << endl;
GetTrees(i);
return 0;
}
cout <<"perfect"<<endl;
return 0;
}

【Codeforces Round #453 (Div. 2) C】 Hashing Trees的更多相关文章

  1. 【Codeforces Round #453 (Div. 2) A】 Visiting a Friend

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 维护最右端的端点就好. [代码] #include <bits/stdc++.h> using namespace st ...

  2. 【Codeforces Round #453 (Div. 2) B】Coloring a Tree

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从根节点开始. 显然它是什么颜色.就要改成对应的颜色.(如果上面已经有某个点传了值就不用改 然后往下传值. [代码] #includ ...

  3. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  4. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  5. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  6. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  7. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  8. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  9. 【Codeforces Round #423 (Div. 2) A】Restaurant Tables

    [Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...

随机推荐

  1. ios 文件上传, post数据

    转自:http://www.maxiaoguo.com/clothes/267.html 一.文件下载 获取资源文件大小有两张方式 1. HTTP HEAD方法 NSMutableURLRequest ...

  2. Anatomy of an IIS7 configuration path

    The concept of configuration paths is fundamental to managing and operating an IIS server, so I want ...

  3. html2canvas截取页面

    1.下载html2canvas.js 2.引入 3.修改html2canvas支持远程图片处理 function ImageContainer(src, cors) { this.src = src; ...

  4. 回顾Abstract和Virtual的用法

    今天坐班车的时候,突然就想起来这俩个货了:仔细缕缕,居然越缕越乱较: 上代码吧: using System; using System.Collections.Generic; using Syste ...

  5. java jframe关闭窗口

    frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { i ...

  6. java 返回json格式的数据

    1 阿里巴巴的fastjson import com.alibaba.fastjson.JSON; 使用的时候 JSON.toJSON(list); 2  Gson 解析json数据 import c ...

  7. Bundles软件

    Bundle 称为:软件集 或 打包捆绑软件(软件束) Bundle就是一组包含了文件集,软件包或许可程序产品的软件,它们组合在一起为了实现一个特定的功能     快速来列出系统bundle软件 sm ...

  8. Linux下搭建iSCSI共享存储详细步骤(服务器模拟IPSAN存储)

    一.简介 iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的.可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够 ...

  9. 【Redis哨兵集群】

    目录 开始配置主从复制 开始配置Redis Sentinel @ *** 在开始之前,我们先来看看Redis的主从复制 主从复制原理: 从服务器向主服务器发送SYNC命令. 主服务器接到SYNC命令后 ...

  10. WP8 学习笔记(002_应用程序结构)

    下图是微软官方给出的WP8应用程序执行顺序: 在App.XAML.CS中,有程序主要步骤的函数 // 应用程序启动(例如,从“开始”菜单启动)时执行的代码 // 此代码在重新激活应用程序时不执行 pr ...