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

【题意】

在这里输入题意

【题解】

显然只有当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. P1328 生活大爆炸版石头剪刀布

    题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...

  2. 分享一段官date函数用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Callback<> and Bind()

    Callback<> and Bind() Introduction The templated base::Callback<> class is a generalized ...

  4. Ubuntu18.04上使用LLDB调试Chromium Android C++代码。

    ###动机###Chromium Android源代码庞大且复杂.在调试器LLDB下能帮助我们更好的理解代码流程.介绍使用LLDB调试器调试android上chromium的C++代码. [1] 编译 ...

  5. 技嘉H81M-DS2 主板安装 XP方法,及网卡驱动安装

    这是微软联合厂家封杀XP的结果,目的很简单,微软只想把你驱赶到WIN7.WIN8上去. 16.7.18 技嘉H81M-S1, G3260 安装XP系统 *BIOS 修改 Storage Boot Op ...

  6. LG Gram 2018 z980 白

    因为今年8代处理器i5的双核变成了四核,感觉是个换电脑的好时机,本来打算买macbook,但是6月的发布会并没有发布,于是开始寻找一些比较有特点的笔记本电脑. 了解了这样一款笔记本 LG GRAM 1 ...

  7. C++入门之HelloWorld

    1.在VS2017上新建一个C++空白项目,命名为hello 2.在资源文件下新建添加新建项main.cpp 3.在main.cpp中编写hello world输出代码 #include<std ...

  8. 洛谷 P1964 【mc生存】卖东西

    P1964 [mc生存]卖东西 题目背景 服务器好好玩 题目描述 lcy0x1去服务器的系统商店卖东西. 一个人的背包有21格. 一开始他的背包里有m件不同的物品(不能卖). 他要卖n种物品,每种物品 ...

  9. hdoj-1421-搬寝室【DP】

    搬寝室 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  10. html --- rem 媒体查询

    rem是一种相对长度单位,参考的基准是<html>标签定义的font-size. viewport 做移动端的h5,通常会在HTML文件中指定一个<meta>标签: <m ...