【Codeforces Round #453 (Div. 2) C】 Hashing Trees
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
显然只有当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的更多相关文章
- 【Codeforces Round #453 (Div. 2) A】 Visiting a Friend
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 维护最右端的端点就好. [代码] #include <bits/stdc++.h> using namespace st ...
- 【Codeforces Round #453 (Div. 2) B】Coloring a Tree
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 从根节点开始. 显然它是什么颜色.就要改成对应的颜色.(如果上面已经有某个点传了值就不用改 然后往下传值. [代码] #includ ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- rac_grid自检提示缺少pdksh-5.2包
原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...
- Redis封装之Set
RedisSetService: /// <summary> /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据 /// 1.共同好友.二度好友 /// 2. ...
- orm 通用方法——RunProc调用存储过程
该方法暂不支持带返回值的存储过程,期待能人补充指点. 定义代码: /** * 描述:执行存储过程 * 作者:Tianqi * 日期:2014-09-16 * param:rs orm.RawSeter ...
- POJ 3256 DFS水题
枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- Sqoop1与Sqoop2的比较
1.sqoop1和sqoop2是两个不同的版本,它们是完全不兼容的. 2.版本划分方式:Apache 1.4.x 之后的版本属于sqoop1,1.99.x之上的版本属于sqoop2. 3.与sqoop ...
- C++中explicit关键字作用
explicit是c++中不太常用的一个关键字,其作用是用于修饰构造函数,告诉编译器定义对象时不做隐式转换. 举例说明: include <iostream> include <st ...
- JS jQuery查看系统中安装的字体
1.下载插件:FontDetect插件 地址:http://www.lalit.org/lab/javascript-css-font-detect/ 或者复制以下代码到fontdetect.js: ...
- 11/1 NOIP 模拟赛
11.1 NOIP 模拟赛 期望得分:50:实际得分:50: 思路:暴力枚举 + 快速幂 #include <algorithm> #include <cstring> #in ...
- Cocos2d-x手机游戏开发与项目实践具体解释_随书代码
Cocos2d-x手机游戏开发与项目实战具体解释_随书代码 作者:沈大海 因为原作者共享的资源为UTF-8字符编码.下载后解压在win下显示乱码或还出现文件不全问题,现完整整理,解决全部乱码问题,供 ...
- SQL查询表中的用那些索引
方法1. 使用系统表 -- 查询一个表中的索引及索引列 USE AdventureWorks2008 GO SELECT indexname = a.name , tablename = c. n ...