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

【题意】

在这里输入题意

【题解】

显然只有当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. CAShapeLayer的简单介绍以及基本使用

    1.CAShapeLayer简单介绍  1.1CAShapeLayer继承于CALayer,能够使用CALayer的全部属性值:    1.2CAShapeLayer须要贝塞尔曲线配合使用才有意义(也 ...

  2. BZOJ 1050 枚举+并查集

    思路: 枚举最大边 像Kruskal一样加边 每回更新一下 就搞定了- //By SiriusRen #include <cstdio> #include <cstring> ...

  3. HTTP 与 HTTPS

    https就是http和TCP之间有一层SSL层,这一层的实际作用是防止钓鱼和加密. 防止钓鱼通过网站的证书,网站必须有CA证书,证书类似于一个解密的签名. 另外是加密,加密需要一个密钥交换算法,双方 ...

  4. UVA And Then There Was One

    约瑟夫环问题,只不过每次删除一个后,在移m的倍数. #include <iostream> #include <cstdio> #include <cstring> ...

  5. jquery表单动态添加元素及PHP处理

    tijiao.php页面代码: if(isset($_POST['cp1'])){    echo '<pre>';    print_r($_POST); $num=((count($_ ...

  6. Node.js转化GBK编码 - iconv-lite

    node当使用node获取GBK编码的数据时,nodejs仅仅支持utf-8,node没有提供转换编码的原生支持,有倒是有一个模块iconv能干这个事,但须要本地方法,VC++库的支持.国外有个大牛写 ...

  7. OpenCASCADE Job - 武汉中南

    中南设计集团(武汉)工程技术研究院有限公司是中南工程咨询设计集团有限公司(以下简称“中南设计集团”)打造的工程技术研发和科研创新平台,为中南设计集团旗下全资子公司,于2018年2月成立.公司业务范围涵 ...

  8. Android Studio 解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  9. MySql_Learn

    1 id 自增长  auto_increment 2 获取当前时间 now() 3 新增字段 修改字段名称 简单分页功能  limit 10 offset 20;  查询第21到30条数据 selec ...

  10. 小程序block总结

    小程序block总结 1.block并不是一个组件,它仅仅是一个包装元素,不会在页面中做任何渲染,只接受控制属性. 2.因为 wx:if 是一个控制属性,需要将它添加到一个标签上.如果要一次性判断多个 ...