zoukankan      html  css  js  c++  java
  • UVa10410代码

    这里就不加太多的注释了,想一想就能明白代码的目的

    // UVa 10410 
    #include <iostream> 
    #include <cstdio>
    #include <cstring>
    #include <vector> 
    #include <stack> 
    using namespace std;
    
    const int maxn = 1000 + 5;
    
    vector<int> node[maxn];
    int pos[maxn]; 
    
    int main() {
      int N, m;
      while (scanf("%d", &N) == 1) {
        for (int i = 1; i <= N; ++i)
          node[i].clear();
        for (int i = 1; i <= N; ++i) { // bfs
          scanf("%d", &m);
          pos[m] = i;    
        }
        stack<int> st;
        int b; 
        scanf("%d", &b);
        st.push(b);
        for (int i = 1; i < N; ++i) { // dfs 
          scanf("%d", &b);
          while (1) {
            int a = st.top();
            if (pos[a]+1 < pos[b] || (pos[a]+1 == pos[b] && a > b) || pos[a] == 1) {
              node[a].push_back(b);
              st.push(b);     
              break; 
            }
            else 
              st.pop();
          }
        }
        for (int i = 1; i <= N; ++i) {
          printf("%d:", i); 
          for (int j = 0; j < node[i].size(); ++j)
            printf(" %d", node[i][j]);
          printf("
    "); 
        }
      }
      return 0;
    }
  • 相关阅读:
    冲刺1
    第九周
    课堂作业
    团队项目典型用户与用户场景分析
    第八周
    梦断代码阅读笔记03
    tab页的使用方法
    校园服务nabcd需求分析
    第七周
    mysql下载以及安装
  • 原文地址:https://www.cnblogs.com/yifeiWa/p/10975364.html
Copyright © 2011-2022 走看看