10410 这题说的是给了一棵多叉树的 bfs遍历轨迹 和dfs 遍历 轨迹 在父节点向叶子节点扩展的时候优先遍历编号较小的节点。我还原出这课树特殊判定

根据bfs的顺序来建立这课树,用一个队列安排要构造的这课子树 条件是这棵树拥有孩子节点,判定这个点的下一层孩子ij(i<j)节点之间的在dfs中  的间隔节点 将这些点分配给i节点因为可以知道这些节点肯定是i的孩子节点或者孙子节点 如果这些在dfs中 间 隔 的 节 点 个 数 大 于 0 就 把 i 点 推 入 队 列 当 中 ( 因 为 i 节 点有孩子节点) 这样不断的去构造这棵树的子树,还有就是当一层当中只有一个节点的时候且这个节点的编号比孩子节点来得大的时候这样就得特判 因为像我那样就直接将他们归为一层了要进行特判的条件他们有同样的祖先且前者大于后者这样后者就一定是前者的孩子而不可能是后者的兄弟节点

  1. #include <string.h>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7. const int maxn = ;
  8. vector<int> map[maxn];
  9. int dfs[maxn],bfs[maxn],n;
  10. int locdfs[maxn],locbfs[maxn],per[maxn];
  11. int work(int a, int b){
  12. int num = ;
  13. for( int i = locdfs[a]+ ; i<n; ++ i ){
  14. if( per[dfs[i]] != per[a] || dfs[i] == b )break;
  15. per[dfs[i]] = a;
  16. num++;
  17. }
  18. return num;
  19. }
  20. void solve(){
  21.  
  22. queue<int>Q;
  23. Q.push(dfs[]);
  24. while(!Q.empty()){
  25. int t = Q.front();
  26. Q.pop();
  27. int start = locdfs[t] + ;
  28. int F = locbfs[dfs[start]];
  29. for( int i = F ; i <n ; i++ ){
  30. int t1 = bfs[i],t2 = bfs[i+];
  31. if(per[t1]!=t)break;
  32. if(t1>t2){
  33. int num=work(t1,);
  34. if(num>) Q.push(t1);
  35. map[t].push_back(t1); break;
  36. }
  37. int num = work(t1,t2);
  38. if(num>) Q.push(t1);
  39. map[t].push_back(t1);
  40. }
  41. }
  42. }
  43. int main(){
  44.  
  45. while( scanf("%d",&n) == ){
  46.  
  47. for(int i = ; i <= n ; ++ i)
  48. map[i].clear();
  49. for(int i = ; i < n ; ++ i){
  50. scanf("%d",&bfs[i]);
  51. locbfs[bfs[i]] = i ;
  52. }
  53. bfs[n] = ;
  54. for(int i = ; i < n ; ++ i){
  55. scanf("%d",&dfs[i]);
  56. locdfs[dfs[i]] = i ;
  57. }
  58. dfs[n] = ;
  59. for( int i = ; i <=n ; ++ i)
  60. per[i] = dfs[];
  61. solve();
  62. for( int i = ; i <= n ; ++ i){
  63. printf("%d:",i);
  64. for( int j = ; j <map[i].size() ; ++ j )
  65. printf(" %d",map[i][j]);
  66. printf("\n");
  67. }
  68. }
  69.  
  70. return ;
  71. }
  72. /*
  73. 4 3 5 1 2 8 6 7 9 10
  74. 4 3 1 7 10 2 6 9 5 8
  75. */

10895 这题比较简单说的是给了一个矩阵然后转置后输出

  1. #include <cstdio>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <queue>
  5. using namespace std;
  6. const int maxn=;
  7. struct node{
  8. int column,value;
  9. node(int a= ,int b= ){
  10. column = a; value = b;
  11. }
  12. bool operator <(const node &A)const{
  13. return column>A.column;
  14. }
  15. }T[maxn];
  16. priority_queue<node>ans[][maxn];
  17. int main(){
  18. int n,m;
  19. while(scanf("%d%d",&n,&m)==){
  20. for( int i = ; i <= n ; ++ i ) while(!ans[][i].empty())ans[][i].pop();
  21. for( int i = ; i <= m ; ++i ) while(!ans[][i].empty())ans[][i].pop();
  22. for( int i= ;i <= n ; i++){
  23. int num;
  24. scanf("%d",&num);
  25. for( int j = ; j < num ; ++ j)
  26. scanf("%d",&T[j].column);
  27. for( int j = ; j< num ; ++ j)
  28. scanf("%d",&T[j].value);
  29. for( int j= ; j< num ; ++ j)
  30. ans[][i].push(T[j]);
  31. }
  32. for( int i = ; i <=n ; ++ i ){
  33. while(!ans[][i].empty()){
  34. node t = ans[][i].top(); ans[][i].pop();
  35. ans[][t.column].push(node(i,t.value));
  36. }
  37. }
  38. printf("%d %d\n",m,n);
  39. for( int i = ; i <= m ; i++ ){
  40. int num = ans[][i].size();
  41. for( int j = ; j< num ; j++){
  42. T[j]=ans[][i].top(); ans[][i].pop();
  43. }
  44. printf("%d",num);
  45. for( int j = ; j < num ; ++ j){
  46. printf(" %d",T[j].column);
  47. }
  48. printf("\n");
  49. if(num>){
  50. for( int j = ; j < num- ; ++ j)
  51. printf("%d ",T[j].value);
  52. printf("%d",T[num-].value);
  53. }
  54. printf("\n");
  55. }
  56. }
  57.  
  58. return ;
  59. }

AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures的更多相关文章

  1. 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   ...

  2. 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 ...

  3. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 7. Graph Algorithms and Implementation Techniques

    uva 10803 计算从任何一个点到图中的另一个点经历的途中必须每隔10千米 都必须有一个点然后就这样 floy 及解决了 ************************************* ...

  4. Sequential Minimal Optimization: A Fast Algorithm for Training Support Vector Machines 论文研读

    摘要 本文提出了一种用于训练支持向量机的新算法:序列最小优化算法(SMO).训练支持向量机需要解决非常大的二 次规划(QP)优化问题.SMO 将这个大的 QP 问题分解为一系列最小的 QP 问题.这些 ...

  5. [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 ...

  6. 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 ...

  7. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  8. 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, ...

  9. 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, ...

随机推荐

  1. python pytest测试框架介绍三

    之前介绍了pytest以xUnit形式来写用例,下面来介绍pytest特有的方式来写用例 1.pytest fixture实例1 代码如下 from __future__ import print_f ...

  2. C# 验证XML

    一.验证XML文档 若要验证 XML 文档,需要构造一个 XmlReaderSettings 对象,其中包含用于验证 XML 文档的 XML 架构定义语言 (XSD) 架构.Schema是用于描述和规 ...

  3. jquery如何让checkbox如何取消勾选

    1.取消勾选 $("checkbox").attr("checked", false); 2.勾选 $("checkbox").attr(& ...

  4. you do not have permission to pull from the repository解决方法

    使用git进行项目的版本管理,换了台电脑,配置了账号和邮箱后,pull一个私有项目的时候,发现一个问题: 原因分析: 这是由于没有设置Gitee的SSH公钥.在未设置SSH公钥的情况下,可以使用git ...

  5. thinkCMF----公共模板的引入

    这个主要用于前台模板的 头部和底部分离: 具体引入方法: <include file="public@source"/> <include file=" ...

  6. mysql数据库恢复

    数据库恢复注意事项: # 数据恢复和字符集关联很大,如果字符集不正确会导致恢复的数据乱码. #MySQL命令和source命令恢复数据库的原理就是把文件的SQL语句,在数据库重新执行的过程. 1.利用 ...

  7. python字典获取最大值的键的值

    有时我们需要字典中数值最大的那个键的名字,使用max(dict, key=dict.get)函数非常的方便 key_name = max(my_dict, key=my_dict.get) 获取之后你 ...

  8. CodeForces - 617E XOR and Favorite Number 莫队算法

    https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...

  9. iOS - UITableView 编辑(cell的插入, 删除, 移动)

    UITableView Cell的插入/删除 核心API Class : UITableView Delegate : UITableViewDataSource, UITableViewDelega ...

  10. 单例模式:Qt本身就提供了专门的宏 Q_GLOBAL_STATIC 通过这个宏不但定义简单,还可以获得线程安全性

    标题起的是有点大 主要是工作和学习中,遇到些朋友,怎么说呢,代码不够Qt化 可能是由于他们一开始接触的是 Java MFC 吧 接触 Qt 7个年头了 希望我的系列文章能抛砖引玉吧 单例模式 很多人洋 ...