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

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

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

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. yum 仓库配置

    [base]name=aliyum basebaseurl=https://mirrors.aliyun.com/centos/6/os/x86_64/                        ...

  2. maven入门2

    1.修改maven本地仓库位置 没有效果,在新建项目时还是转跳到默认配置 在默认仓库位置添加修改后的setting文件,失败 修改成功,原因是前面修改的是setting而我们需要修改的是default ...

  3. MySQL备份工具percona-xtrabackup安装

    1.安装xtrabackup的yum源 rpm -ivh https://www.percona.com/redir/downloads/percona-release/redhat/latest/p ...

  4. java-访问控制修饰符

    访问权限 public    任何情况都可以访问 默认包 本包范围内可以访问到 protect       同一个包里的所有类所可以访问:所有子类(子类可以不和父类在同一个包)都可以访问 privat ...

  5. phpstorm 安装XeDbug

    第一步:根据phpinfo()下载相对应的Xdebug插件,Xdebug下载路径https://xdebug.org/download.php 第二步:将下载好的Xdebug放到 G:\Service ...

  6. iOS-修改modal出来的控制器的大小

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    static BOOL sh ...

  7. POJ:3292-Semi-prime H-numbers(艾氏筛选法拓展)

    Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10466 Accepted: 4665 ...

  8. POJ:2367-Cleaning Shifts

    传送门:http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Sub ...

  9. 笔记-python-standard library-16.3 time

    笔记-python-standard library-16.3 time 1.      time 1.1.    开始 time模块中时间表现的格式主要有三种: timestamp时间戳,时间戳表示 ...

  10. ASP.NET 使用 MySQL

    基本是通用的 C#与MySQL的交互, 先添加MySQL.Data.dll(位于MySQL安装目录下的Connector NET 8.0\Assemblies${version}目录下)引用, 之后代 ...