zoukankan      html  css  js  c++  java
  • AC日记——队列安排 洛谷 P1160

    队列安排

    思路:

      链表裸题;

    来,上代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    
    using namespace std;
    
    #define maxn 100005
    
    struct ListType {
        int pre,suc,key;
    };
    struct ListType list[maxn<<1];
    
    int tot=2,n,m,sta=0,End=1,to[maxn];
    
    inline void in(int &now)
    {
        char Cget=getchar();now=0;
        while(Cget>'9'||Cget<'0') Cget=getchar();
        while(Cget>='0'&&Cget<='9')
        {
            now=now*10+Cget-'0';
            Cget=getchar();
        }
    }
    
    int main()
    {
        to[1]=2;
        list[sta].suc=2;
        list[End].pre=2;
        list[2].key=1;
        list[2].pre=sta;
        list[2].suc=End;
        in(n);int v,p;
        for(int i=2;i<=n;i++)
        {
            in(v),in(p);
            to[i]=++tot;
            list[tot].key=i;
            int pos=to[v];
            if(p)
            {
                int cur=list[pos].suc;
                list[pos].suc=tot;
                list[tot].pre=pos;
                list[tot].suc=cur;
                list[cur].pre=tot;
            }
            else
            {
                int cur=list[pos].pre;
                list[pos].pre=tot;
                list[tot].suc=pos;
                list[tot].pre=cur;
                list[cur].suc=tot;
            }
        }
        in(m);
        while(m--)
        {
            in(v);
            if(to[v])
            {
                int pos=to[v];
                to[v]=0;
                list[list[pos].pre].suc=list[pos].suc;
                list[list[pos].suc].pre=list[pos].pre;
            }
        }
        for(int now=list[sta].suc;now!=End;now=list[now].suc)
        {
            now!=list[End].pre?printf("%d ",list[now].key):printf("%d
    ",list[now].key);
        }
        return 0;
    }
  • 相关阅读:
    171. Excel Sheet Column Number (Easy)
    349. Intersection of Two Arrays (Easy)
    453. Minimum Moves to Equal Array Elements (Easy)
    657. Judge Route Circle (Easy)
    CSS笔记
    保存页面状态
    UI开发总结
    ubuntu 下配置munin
    反向代理配置
    JavaScript 高级程序设计第二版
  • 原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6735286.html
Copyright © 2011-2022 走看看