【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个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- css footer not displaying at the bottom of the page
https://stackoverflow.com/questions/15960290/css-footer-not-displaying-at-the-bottom-of-the-page The ...
- Java中二进制字节与十六进制互转
在Java中字节与十六进制的相互转换主要思想有两点: 1.二进制字节转十六进制时,将字节高位与0xF0做"&"操作,然后再左移4位,得到字节高位的十六进制A;将字节低位与0 ...
- 3.菜鸟教你一步一步开发 web service 之 axis 服务端创建
转自:https://blog.csdn.net/shfqbluestone/article/details/37610601 第一步,新建一个工程,如图: 选 Java 写一个工程名,选择好工程路径 ...
- BZOJ 1066 Dinic
思路: 网络流 建边比较麻烦 //By SiriusRen #include <queue> #include <cstdio> #include <cstring> ...
- 简单的字符串压缩--C代码
#include <stdio.h> #include <string.h> bool compress(char *str) { char *p=str,c; ; if(!s ...
- .Net Web开发技术栈 收藏
原文:http://www.cnblogs.com/1996V/p/7700087.html#!comments 有很多朋友有的因为兴趣,有的因为生计而走向了.Net中,有很多朋友想学,但是又不知道怎 ...
- 多路径软件常用操作(MPIO)
一:查看存储盘的路径 1. 查看MPIO的存储盘的路径 # lspath (适用于所有存储的MPIO路径查询) # mpio_get_config -Av (适用于DS3K/DS4K的MPIO路径查询 ...
- Spring Cloud学习笔记【一】Eureka服务注册与发现
Spring Cloud Eureka 是 Spring Cloud Netflix 微服务套件的一部分,基于 Netflix Eureka 做了二次封装,主要负责完成微服务架构中的服务治理功能,服务 ...
- HDU——T 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 Time Limit: 4000/2000 MS (Java/Others) Memory Limi ...
- 从头认识Spring-2.4 基于java的标准注解装配-@Inject(2)-通过set方法或者其它方法注入
这一章节我们来讨论一下基于java的标准注解装配标签@Inject是如何通过通过set方法或者其它方法注入? 在使用@Inject标签之前.我们须要在pom文件中面增加以下的代码: <depen ...