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

【题意】

在这里输入题意

【题解】

显然只有当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层只在最左边那个节点接

【代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e5;
  4. int a[N+50],h;
  5. vector <int> tree[2];
  6. void GetTrees(int idx){
  7. tree[0].push_back(0);
  8. tree[1].push_back(0);
  9. int pre1 = 1,pre2 = -1,now = 1;
  10. for (int i = 2;i <= idx-1;i++){
  11. for (int j = 1;j <= a[i];j++){
  12. tree[0].push_back(pre1);
  13. tree[1].push_back(pre1);
  14. }
  15. int cnt = 0;
  16. for (int j = 1;j <= a[i];j++){
  17. now++;cnt++;
  18. if (cnt==1) pre1 = now;
  19. if (cnt==2) pre2 = now;
  20. }
  21. }
  22. for (int i = 1;i <= a[idx];i++){
  23. if (i&1) {
  24. tree[0].push_back(pre1);
  25. }else tree[0].push_back(pre2);
  26. tree[1].push_back(pre1);
  27. }
  28. for (int i = 1;i <= a[idx];i++){
  29. now++;
  30. pre1 = now;
  31. }
  32. for (int i = idx+1;i <= h;i++){
  33. for (int j = 1;j <= a[i];j++){
  34. tree[0].push_back(pre1);
  35. tree[1].push_back(pre1);
  36. }
  37. for (int j = 1;j <= a[i];j++){
  38. now++;
  39. pre1 = now;
  40. }
  41. }
  42. for (int x:tree[0]){
  43. cout << x <<' ';
  44. }
  45. cout << endl;
  46. for (int x:tree[1]){
  47. cout << x <<' ';
  48. }
  49. }
  50. int main(){
  51. #ifdef LOCAL_DEFINE
  52. freopen("rush_in.txt", "r", stdin);
  53. #endif
  54. ios::sync_with_stdio(0),cin.tie(0);
  55. cin >> h;h++;
  56. for (int i = 1;i <= h;i++) cin >> a[i];
  57. for (int i = 2;i <= h;i++)
  58. if (a[i]>=2 && a[i-1]>=2){
  59. cout << "ambiguous" << endl;
  60. GetTrees(i);
  61. return 0;
  62. }
  63. cout <<"perfect"<<endl;
  64. return 0;
  65. }

【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. rac_grid自检提示缺少pdksh-5.2包

    原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  2. Redis封装之Set

    RedisSetService: /// <summary> /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据 /// 1.共同好友.二度好友 /// 2. ...

  3. orm 通用方法——RunProc调用存储过程

    该方法暂不支持带返回值的存储过程,期待能人补充指点. 定义代码: /** * 描述:执行存储过程 * 作者:Tianqi * 日期:2014-09-16 * param:rs orm.RawSeter ...

  4. POJ 3256 DFS水题

    枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  5. Sqoop1与Sqoop2的比较

    1.sqoop1和sqoop2是两个不同的版本,它们是完全不兼容的. 2.版本划分方式:Apache 1.4.x 之后的版本属于sqoop1,1.99.x之上的版本属于sqoop2. 3.与sqoop ...

  6. C++中explicit关键字作用

    explicit是c++中不太常用的一个关键字,其作用是用于修饰构造函数,告诉编译器定义对象时不做隐式转换. 举例说明: include <iostream> include <st ...

  7. JS jQuery查看系统中安装的字体

    1.下载插件:FontDetect插件  地址:http://www.lalit.org/lab/javascript-css-font-detect/ 或者复制以下代码到fontdetect.js: ...

  8. 11/1 NOIP 模拟赛

    11.1 NOIP 模拟赛 期望得分:50:实际得分:50: 思路:暴力枚举 + 快速幂 #include <algorithm> #include <cstring> #in ...

  9. Cocos2d-x手机游戏开发与项目实践具体解释_随书代码

    Cocos2d-x手机游戏开发与项目实战具体解释_随书代码 作者:沈大海  因为原作者共享的资源为UTF-8字符编码.下载后解压在win下显示乱码或还出现文件不全问题,现完整整理,解决全部乱码问题,供 ...

  10. SQL查询表中的用那些索引

    方法1. 使用系统表   -- 查询一个表中的索引及索引列 USE AdventureWorks2008 GO SELECT indexname = a.name , tablename = c. n ...