AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures
10410 这题说的是给了一棵多叉树的 bfs遍历轨迹 和dfs 遍历 轨迹 在父节点向叶子节点扩展的时候优先遍历编号较小的节点。我还原出这课树特殊判定
根据bfs的顺序来建立这课树,用一个队列安排要构造的这课子树 条件是这棵树拥有孩子节点,判定这个点的下一层孩子ij(i<j)节点之间的在dfs中 的间隔节点 将这些点分配给i节点因为可以知道这些节点肯定是i的孩子节点或者孙子节点 如果这些在dfs中 间 隔 的 节 点 个 数 大 于 0 就 把 i 点 推 入 队 列 当 中 ( 因 为 i 节 点有孩子节点) 这样不断的去构造这棵树的子树,还有就是当一层当中只有一个节点的时候且这个节点的编号比孩子节点来得大的时候这样就得特判 因为像我那样就直接将他们归为一层了要进行特判的条件他们有同样的祖先且前者大于后者这样后者就一定是前者的孩子而不可能是后者的兄弟节点
- #include <string.h>
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- const int maxn = ;
- vector<int> map[maxn];
- int dfs[maxn],bfs[maxn],n;
- int locdfs[maxn],locbfs[maxn],per[maxn];
- int work(int a, int b){
- int num = ;
- for( int i = locdfs[a]+ ; i<n; ++ i ){
- if( per[dfs[i]] != per[a] || dfs[i] == b )break;
- per[dfs[i]] = a;
- num++;
- }
- return num;
- }
- void solve(){
- queue<int>Q;
- Q.push(dfs[]);
- while(!Q.empty()){
- int t = Q.front();
- Q.pop();
- int start = locdfs[t] + ;
- int F = locbfs[dfs[start]];
- for( int i = F ; i <n ; i++ ){
- int t1 = bfs[i],t2 = bfs[i+];
- if(per[t1]!=t)break;
- if(t1>t2){
- int num=work(t1,);
- if(num>) Q.push(t1);
- map[t].push_back(t1); break;
- }
- int num = work(t1,t2);
- if(num>) Q.push(t1);
- map[t].push_back(t1);
- }
- }
- }
- int main(){
- while( scanf("%d",&n) == ){
- for(int i = ; i <= n ; ++ i)
- map[i].clear();
- for(int i = ; i < n ; ++ i){
- scanf("%d",&bfs[i]);
- locbfs[bfs[i]] = i ;
- }
- bfs[n] = ;
- for(int i = ; i < n ; ++ i){
- scanf("%d",&dfs[i]);
- locdfs[dfs[i]] = i ;
- }
- dfs[n] = ;
- for( int i = ; i <=n ; ++ i)
- per[i] = dfs[];
- solve();
- for( int i = ; i <= n ; ++ i){
- printf("%d:",i);
- for( int j = ; j <map[i].size() ; ++ j )
- printf(" %d",map[i][j]);
- printf("\n");
- }
- }
- return ;
- }
- /*
- 4 3 5 1 2 8 6 7 9 10
- 4 3 1 7 10 2 6 9 5 8
- */
10895 这题比较简单说的是给了一个矩阵然后转置后输出
- #include <cstdio>
- #include <string.h>
- #include <iostream>
- #include <queue>
- using namespace std;
- const int maxn=;
- struct node{
- int column,value;
- node(int a= ,int b= ){
- column = a; value = b;
- }
- bool operator <(const node &A)const{
- return column>A.column;
- }
- }T[maxn];
- priority_queue<node>ans[][maxn];
- int main(){
- int n,m;
- while(scanf("%d%d",&n,&m)==){
- for( int i = ; i <= n ; ++ i ) while(!ans[][i].empty())ans[][i].pop();
- for( int i = ; i <= m ; ++i ) while(!ans[][i].empty())ans[][i].pop();
- for( int i= ;i <= n ; i++){
- int num;
- scanf("%d",&num);
- for( int j = ; j < num ; ++ j)
- scanf("%d",&T[j].column);
- for( int j = ; j< num ; ++ j)
- scanf("%d",&T[j].value);
- for( int j= ; j< num ; ++ j)
- ans[][i].push(T[j]);
- }
- for( int i = ; i <=n ; ++ i ){
- while(!ans[][i].empty()){
- node t = ans[][i].top(); ans[][i].pop();
- ans[][t.column].push(node(i,t.value));
- }
- }
- printf("%d %d\n",m,n);
- for( int i = ; i <= m ; i++ ){
- int num = ans[][i].size();
- for( int j = ; j< num ; j++){
- T[j]=ans[][i].top(); ans[][i].pop();
- }
- printf("%d",num);
- for( int j = ; j < num ; ++ j){
- printf(" %d",T[j].column);
- }
- printf("\n");
- if(num>){
- for( int j = ; j < num- ; ++ j)
- printf("%d ",T[j].value);
- printf("%d",T[num-].value);
- }
- printf("\n");
- }
- }
- return ;
- }
AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures的更多相关文章
- AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 6. Mathematical Concepts and Methods
uva 106 这题说的是 说计算 x^2 + y^2 = z^2 xyz 互质 然后计算个数和 在 N内 不在 勾股数之内的数的个数 然后去找需要的 维基百科上 看到 另 n*m*2 =b ...
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming
10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=sho ...
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 7. Graph Algorithms and Implementation Techniques
uva 10803 计算从任何一个点到图中的另一个点经历的途中必须每隔10千米 都必须有一个点然后就这样 floy 及解决了 ************************************* ...
- Sequential Minimal Optimization: A Fast Algorithm for Training Support Vector Machines 论文研读
摘要 本文提出了一种用于训练支持向量机的新算法:序列最小优化算法(SMO).训练支持向量机需要解决非常大的二 次规划(QP)优化问题.SMO 将这个大的 QP 问题分解为一系列最小的 QP 问题.这些 ...
- [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]
11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...
- uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)
11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
随机推荐
- python pytest测试框架介绍三
之前介绍了pytest以xUnit形式来写用例,下面来介绍pytest特有的方式来写用例 1.pytest fixture实例1 代码如下 from __future__ import print_f ...
- C# 验证XML
一.验证XML文档 若要验证 XML 文档,需要构造一个 XmlReaderSettings 对象,其中包含用于验证 XML 文档的 XML 架构定义语言 (XSD) 架构.Schema是用于描述和规 ...
- jquery如何让checkbox如何取消勾选
1.取消勾选 $("checkbox").attr("checked", false); 2.勾选 $("checkbox").attr(& ...
- you do not have permission to pull from the repository解决方法
使用git进行项目的版本管理,换了台电脑,配置了账号和邮箱后,pull一个私有项目的时候,发现一个问题: 原因分析: 这是由于没有设置Gitee的SSH公钥.在未设置SSH公钥的情况下,可以使用git ...
- thinkCMF----公共模板的引入
这个主要用于前台模板的 头部和底部分离: 具体引入方法: <include file="public@source"/> <include file=" ...
- mysql数据库恢复
数据库恢复注意事项: # 数据恢复和字符集关联很大,如果字符集不正确会导致恢复的数据乱码. #MySQL命令和source命令恢复数据库的原理就是把文件的SQL语句,在数据库重新执行的过程. 1.利用 ...
- python字典获取最大值的键的值
有时我们需要字典中数值最大的那个键的名字,使用max(dict, key=dict.get)函数非常的方便 key_name = max(my_dict, key=my_dict.get) 获取之后你 ...
- CodeForces - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
- iOS - UITableView 编辑(cell的插入, 删除, 移动)
UITableView Cell的插入/删除 核心API Class : UITableView Delegate : UITableViewDataSource, UITableViewDelega ...
- 单例模式:Qt本身就提供了专门的宏 Q_GLOBAL_STATIC 通过这个宏不但定义简单,还可以获得线程安全性
标题起的是有点大 主要是工作和学习中,遇到些朋友,怎么说呢,代码不够Qt化 可能是由于他们一开始接触的是 Java MFC 吧 接触 Qt 7个年头了 希望我的系列文章能抛砖引玉吧 单例模式 很多人洋 ...