CERC2017 H Hidden Hierarchy(树+模拟)
题意:
在一些给定的目录里按要求展开到制定大小并按字典序输出
思路:
因为有目录这个东西,所以想到模拟一个类似字典树的东西,不过这里每个儿子可能有n个节点,而且不能O(1)查询了
代码超长。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); //vector<string>str;//每个编号对应的字符串
string str[ + ];
bool cmp(int a, int b){
return str[a] < str[b];
}
vector<int>v[ + ];//v[i]为i的孩子们
int tol = ;
int vis[ + ];//结尾节点
int vl[ + ];//节点的值
int T;
void insert(vector<string>s, int val){
int root = ;
int sz = s.size();
for(int i = ; i < sz; i++){
//cout << i << " "<<s[i]<<endl;
int flg = ;
for(int j = ; j < (int)v[root].size(); j++){
if(str[v[root][j]] == s[i]){
root = v[root][j];
flg = ;
break;
}
}
if(!flg){
//cout << " bug "<<tol<<endl;
v[root].pb(tol);
str[tol] = s[i];
if(i==(sz-)){
vis[tol] = ;
vl[tol] = val;
}
root = tol++;
}
}
return;
}
int size[ + ];
int readydfs(int root){
int sz = v[root].size();
int res = ;
if(sz == ){
return vl[root];
}
int flg = ;
//cout << root << " "<<str[root]<<endl;
for(int i = ; i < sz; i++){
//cout << v[root][i] << " " << str[v[root][i]]<<endl;
if(vis[v[root][i]] != ){
flg = ;
}
res += readydfs(v[root][i]);
}
if(!flg) vis[root] = ; return vl[root] = res;
}
void dfs(int root, string s, int c){
int sz = v[root].size();
int flg = ;
if(vis[root]==)flg = ;
if(vl[root] < T){
if(vis[root] == ) flg = ;
else flg = ;
}
//cout << s <<endl;
/*if(flg == 0){
cout<<"- "<<s<<"/ "<<vl[root]<<endl;
}*/
if(flg == ){
cout <<" "<<s<<"/ "<<vl[root]<<endl;
return;
}
else if(flg == ){
cout << "+ "<<s<<"/ "<<vl[root]<<endl;
return;
}
sort(v[root].begin(), v[root].end(), cmp);
int vv = ;
for(int i = ; i < sz; i++){
if(vis[v[root][i]]!=){
if(vv &&vl[v[root][i]]>=T){
cout<<"- "<<s<<"/ "<<vl[root]<<endl;
vv = ;
break;
}
//if(flg == 3) dfs(v[root][i], s+"/"+str[v[root][i]], 0); }
}
if(!vv){
for(int i = ; i < sz; i++){
if(vis[v[root][i]]!=){ dfs(v[root][i], s+"/"+str[v[root][i]], ); }
}
}
else cout << "+ "<<s<<"/ "<<vl[root]<<endl;
return;
}
int main() {
tol = ;
str[] = "/";
mem(vis, );
mem(vl, );
ios::sync_with_stdio(false);
int n;
cin >> n;
string tmp;
for(int t = ; t <= n; t++){
int val;
cin >> tmp >> val;
int len = tmp.size();
vector<string>s;
int p = ;
for(int i = ; i < len; i++){
if(i && (tmp[i] == '/')){
s.pb(tmp.substr(p+, i-p-));
p = i;
}
if(i == len - ){
s.pb(tmp.substr(p+, i-p));
}
}
insert(s, val);
}
readydfs();
/*for(int i = 0; i < tol; i++){
cout << i <<" "<<vl[i]<<endl;
}*/
cin >> T;
string s = "";
dfs(, s, );
return ;
}
CERC2017 H Hidden Hierarchy(树+模拟)的更多相关文章
- Gym - 101620H_Hidden Hierarchy(树+模拟)
Hidden Hierarchy 题目链接 题目描述 You are working on the user interface for a simple text-based file explor ...
- hdu_5818_Joint Stacks(线段树模拟)
题目链接:hdu_5818_Joint Stacks 题意: 给你两个栈,多了个合并操作,然后让你模拟 题解: 很容易想到O(1)的单个栈操作,O(n)的合并操作,这样肯定超时,所以我们要将时间复杂度 ...
- 【CF280D】 k-Maximum Subsequence Sum ,线段树模拟费用流
昨天考试被教育了一波.为了学习一下\(T3\)的科技,我就找到了这个远古时期的\(cf\)题(虽然最后\(T3\)还是不会写吧\(QAQ\)) 顾名思义,这个题目其实可以建成一个费用流的模型.我们用流 ...
- 2019牛客暑期多校训练营(第八场)E:Explorer(LCT裸题 也可用线段树模拟并查集维护连通性)
题意:给定N,M,然后给出M组信息(u,v,l,r),表示u到v有[l,r]范围的通行证有效.问有多少种通行证可以使得1和N连通. 思路:和bzoj魔法森林有点像,LCT维护最小生成树. 开始和队友 ...
- hdu3436 splaytree树模拟队列+离散化缩点
数据较大,需要先把每个top不会操作到的段缩成一个点,记录其开始和结束的位置,和top能操作到的点一起建立一颗伸展树模拟 然后就是普通的队列模拟操作 /* 不会被top操作到的区间就缩点 通过spla ...
- poj2828 伸展树模拟
用伸展树模拟插队比线段树快乐3倍.. 但是pojT了.别的oj可以过,直接贴代码. 每次更新时,找到第pos个人,splay到根,然后作为新root的左子树即可 #include<iostrea ...
- C/C++深度优先搜索(递归树模拟)
//C++深度优先搜索(递归树模拟) #define _CRT_SECURE_NO_WARNINGS #include <iostream> #define MAX_N 1000 usin ...
- hdu 5475 模拟计算器乘除 (2015上海网赛H题 线段树)
给出有多少次操作 和MOD 初始值为1 操作1 y 表示乘上y操作2 y 表示除以第 y次操作乘的那个数 线段树的叶子结点i 表示 第i次操作乘的数 将1替换成y遇到操作2 就把第i个结点的值 替换成 ...
- 主席树/线段树模拟归并排序+二分答案(好题)——hdu多校第4场08
用主席树写起来跑的快一点,而且也很傻比,二分答案,即二分那个半径就行 主席树求的是区间<=k的个数 #include<bits/stdc++.h> using namespace s ...
随机推荐
- Pandas常用方法手册
关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 同时我们需要做如下的引入: import pandas as pd 导入数据 pd.read_ ...
- html 鼠标指针讲解
html 鼠标指针 详情可以看https://www.w3school.com.cn/tiy/t.asp?f=csse_cursor 测试代码: <html> <body> & ...
- MVC 统一验证Token demo
/// <summary> /// 获取token /// </summary> /// <param name="staffId"></ ...
- vue根据选择的月份动态展示当前月份的每一天并展示每一天所对应的星期几
我们在开发过程中所遇到的所有的奇奇怪怪的交互美其名曰用(奇)户(葩)体(需)验(求),而产品所谓的良好的交互效果,在我等开发人员眼里不值一提.不屑一顾.讨厌至极! 对于这样的需求,我通常都是: 但胳膊 ...
- 【原创】Android adb错误“'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件。”处理方法
才刚刚接触Android没多久,现在使用adb命令的时候出现错误“'adb' 不是内部或外部命令,也不是可运行的程序或批处理文件.”,如下图所示: 这个问题一般有两种可能: 1.就是没有配置环境变量, ...
- Your Ride Is Here 你的飞碟在这儿 USACO 模拟
1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec 内存限制: 128 MB提交: 9 解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...
- log日志拦截
简介 主要记录一下项目中的日志拦截和异常拦截,由于之前公司项目为单体项目,所使用的日志拦截较为简单,只是用拦截器进行前后对日志的拦截,异常拦截直接使用@ExceptionHandler,而现在公司接口 ...
- crawler 听课笔记 碎碎念 1 初步了解各种选择器极其简单的使用
css中 身份证 id对应# 衣服 class对应 . 图片 pyquery...as pq html= request.get(url=''.....'') doc=pq(html) d ...
- C# 根据年月日计算周次
//day:要判断的日期,WeekStart:1 周一为一周的开始, 2 周日为一周的开始 public static int WeekOfMonth(DateTime day, int WeekSt ...
- Redis Sentinel 高可用机制
内容目录: Sentinel 如何工作的? 核心配置项 怎么选出新 master 的? Sentinel 有多个,具体谁来执行故障转移? Sentinel 是怎么发现 slave 和其他 sentin ...