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 ...
随机推荐
- java小项目之:扫雷,这游戏没有你想的那么简单!
扫雷 我之前分享的小项目和小游戏,电影购票.坦克大战.捕鱼达人.贪吃蛇等,虽然已经是耳熟能详人尽皆知的项目和游戏,但是保不齐真的有人没接触过. 今天分享的这个项目,我不相信没人接触过(仅限80后-00 ...
- NOIP2004普及组第3题 FBI树
/* 1106: NOIP2004普及组第3题 FBI树 时间限制: 1 Sec 内存限制: 128 MB 提交: 10 解决: 9 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 我 ...
- docker-主从服务部署
欢迎访问我的博客http://www.liyblog.top 我的博客里会有更详细的信息,而且留言必回,手把手给你解释不懂的地方 1.mysql部署 mysql镜像拉取 docker pull ...
- AVR单片机教程——LCD1602
本文隶属于AVR单片机教程系列. 显示屏 开发板套件里有两块屏幕,大的是LCD(液晶显示),小的是OLED(有机发光二极管).正与你所想的相反,短小精悍的比较贵,而本讲的主题--LCD1602-- ...
- pymysql总结
一.创建数据库 import pymysql conn = pymysql.connect(host='ip', user='root', password='密码') # 以字典的形式返回操作结果 ...
- Zero down time upgrade with OGG -from 11g to 12c.
High level steps upgrade from 11g to 12c database: 1) Check network between source and target. 2) ...
- (树形DP)Strategic game POJ - 1463
题意: 给你一棵树,树的每一个节点可以守护与其相连的所有边,问你最少用多少个节点可以守护这整棵树 思路: 仔细思考不难发现,要想守护一条边,边的两个端点必须有一个可以被选(两个都选也可以),然后这个问 ...
- Promise.finally
const Gen = (time) => { return new Promise((resolve, reject) => { setTimeout(function () { if( ...
- Elasticsearch如何修改Mapping结构并实现业务零停机
Elasticsearch 版本:6.4.0 一.疑问 在项目中后期,如果想调整索引的 Mapping 结构,比如将 ik_smart 修改为 ik_max_word 或者 增加分片数量 等,但 El ...
- 创建一个区域(Creating an Area) |使用区域 | 高级路由特性 | 精通ASP-NET-MVC-5-弗瑞曼
摘自:http://www.cnblogs.com/chenboyi081/p/4472709.html#tar2015050302 下面的AdminAreaRegistration继承自AreaRe ...