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

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

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

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. linux数据库copy方法

    相信大多数程序员都会遇到数据库copy的问题,下面就总结几种常见的方法,针对有mysql基础的同学参考 方法一:利用sqlyog的copy database的功能,如图 这种最简单,速度比较慢: 方法 ...

  2. 「译」setState如何知道它该做什么?

    本文翻译自:How Does setState Know What to Do? 原作者:Dan Abramov 如果有任何版权问题,请联系shuirong1997@icloud.com 当你在组件中 ...

  3. Python 中关于文件操作的注意事项

    文件操作 #打开文件 f = open('要打开的文件路径',mode = 'r/w/a', encoding = '文件原来写入时的编码') #操作 data = f.read() #读取 f.wr ...

  4. kivy学习二:做一个查询所在地区身份证前6位的小软件

    经过半个月的尝试,终于成功,记录下来备查! 做完之后发现有很多的问题没有解决,请大佬多批评指教! 强烈建议:学习KIVY的查看官方文档 需要用的知识: 1.字典的相关知识 2.kivy的下拉列表(Dr ...

  5. Altium Designer使用5:AD18的DXP在什么地方?

    1.在顶上的菜单栏右击

  6. 006---Django静态文件配置

    静态文件:Js.Css.Fonts.Image等 这个不难.在setting.py文件加一行 # 别名 用户在url地址栏输入127.0.0.1:8000/static/文件 可以直接访问static ...

  7. Postman-CI集成Jenkins(3)

    Postman-CI集成Jenkins(3) Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins Newman 官方说明:Postman's command-l ...

  8. ceph 存储系统

    http://w w w.c s d n 123.com/html/topnews201408/2/4702.htm

  9. 《1024伐木累》-小白篇之丽jie(结束篇)-总章节六

    往期回顾:  机缘巧合,月侠发现了老王和他心仪女孩儿的秘密,这让他倍感愤怒,一年以后,丽姐又在去往老王家的路上,这让月侠感到历史即将重新上演,他想拦住丽姐,可恰巧丽姐手机没电,失去了联系. 小序 有人 ...

  10. 剑指Offer - 九度1368 - 二叉树中和为某一值的路径

    剑指Offer - 九度1368 - 二叉树中和为某一值的路径2013-11-23 03:46 题目描述: 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结 ...