这题本身是个水题,但是写了半天

题意就是给出一个树的生成方式,让你还原这棵树,然后按深度输出结点

这个还原过程还是比较有趣的(没有用递归)

PS:getline的新姿势get

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
const int maxn = 1e6;
int deep[maxn], c[maxn], f[maxn];
string str[maxn];
string tmp;
vector <int> G[maxn];
queue <int> Q;
int main()
{
int fa = , tot = , d = ;
while(getline(cin, str[++tot], ','))
{
getline(cin, tmp, ',');
for(int i = ; i < tmp.length(); i++) c[tot] = c[tot]* + tmp[i] - '';
f[tot] = fa; c[fa]--;
deep[tot] = deep[fa] + ;
if(c[tot] != ) { fa = tot; }
while(c[fa] == ) fa = f[fa];
}
tot--;
for(int i = ; i <= tot; i++) d = max(d, deep[i]);
for(int i = ; i <= tot; i++)
G[f[i]].push_back(i);
cout<<d<<endl;
Q.push();
while(!Q.empty())
{
int N = Q.size();
for(int i = ; i < N; i++)
{
int x = Q.front(); Q.pop();
for(int j = ; j < G[x].size(); j++)
{
int to = G[x][j];
cout<<str[to]<<" ";
Q.push(to);
}
}
cout<<endl;
}
}

Codeforces Round #387 (Div. 2) 747E的更多相关文章

  1. Codeforces Round #387(div 2)

    A =w= B VOV C QoQ D 题意:贝尔兰冬天很冷,那么司机要换上冬天专用轮胎才能开车.假设冬天一共有n天,有一套冬天专用轮胎,仅能使用k天,这套轮胎不管什么温度都能用,而夏天用的轮胎只能在 ...

  2. Codeforces Round #387 (Div. 2) 747F(数位DP)

    题目大意 给出整数k和t,需要产生一个满足以下要求的第k个十六进制数 即十六进制数每一位上的数出现的次数不超过t 首先我们先这样考虑,如果给你了0~f每个数字可以使用的次数num[i],如何求长度为L ...

  3. Codeforces Round #387 (Div. 2) A+B+C+D!

    A. Display Size 水题,暴力(数据都是水题).0:04 int main() { int n; while(~scanf("%d",&n)) { int mi ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. Oracle 使用Nid 修改数据库的DBID 和 Database Name

    How to Change the DBID, DBNAME Using NID Utility (Doc ID 863800.1) Changing the DBID and Database Na ...

  2. jquery 操作css 选择器

    .addClass() 为每个匹配的元素添加指定的样式类名 .addClass(className) className 为每个匹配元素所有增加的一个或多个样式名 .addClass(function ...

  3. redis 面试题

    https://www.cnblogs.com/ftl1012/p/redisExam.html 1. 使用Redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashM ...

  4. 为什么C++编译器不能支持对模板的分离式编译

    首先,一个编译单元(translation unit)是指一个.cpp文件以及它所#include的所有.h文件,.h文件里的代码将会被扩展到包含它的.cpp文件里,然后编译器编译该.cpp文件为一个 ...

  5. 裸机——SD卡

    1.首先要对SD卡有个基础知识 (1) SD = nandflash + 主控IC. 主控IC负责了校验和坏块管理,所以SoC只需要依照时序就可以和SD卡上的主控IC进行数据交换等操作. (2) SD ...

  6. Codeforces Round #458C DP

    C. Travelling Salesman and Special Numbers time limit per test 1 second memory limit per test 256 me ...

  7. C++ 无符号整型和整型的区别

    在Win 7系统中,short 表示的范围为 - 32767到 32767,而无符号的short表示的范围为0 到 65535,其他类型的同理可推导出来,当然,仅当数字不为负的时候才使用无符号类型. ...

  8. Postgres常用命令之增、删、改、查

    增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...

  9. 正则表达式,regular expression, regex, RE

    正则表达式是用来简洁表达一组字符串的表达式 正则表达式可以用来判断某字符串的特征归属

  10. fix34

    public int[] fix34(int[] nums) { int i3=0; int i4=0; int temp=0; while( (i3<nums.length)&& ...