zoukankan      html  css  js  c++  java
  • 洛谷:P1160 队列安排

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int nownum=0,total=0;
    class node{//使用链表
    public:
        int num;
        int flag;
        node * next,*last;//需要保存下一个与上一个,来找到左与右的位置
    
        node(){flag=1;num=++nownum;next=last=NULL;}//初始化
        void show(){
            if(flag)//flag表示不需要输出,被移除的学生
                cout<<num;
            if(next!=NULL){
                if(flag)
                    cout<<" ";//避免多输出空格
                next->show();//下一个
            }
        }
    }list[100000];
    
    
    int main(){
        int i,M,t1,t2;
        int head=0;//保存头部学生的序号
        cin>>total;
        for(i=1;i<total;i++){
            cin>>t1>>t2;
            if(t2){ //右       //根据左与右的排列分别将左与右的学生改变
                list[i].next=list[t1-1].next;
                if(list[t1-1].next!=NULL)
                    list[t1-1].next->last=list+i;
    
                list[t1-1].next=list+i;
                list[i].last=list+t1-1;           
            }else{//左
                list[i].last=list[t1-1].last;
                if(list[t1-1].last!=NULL)
                    list[t1-1].last->next=list+i;
    
                list[t1-1].last=list+i;
                list[i].next=list+t1-1;   
    
                if(t1-1==head){head=i;}//如果分配到头部的左侧,则成为头部
            }
        }
        cin>>M;
        for(i=0;i<M;i++){
            cin>>t1;
            list[t1-1].flag=0;//标记
        }
        list[head].show();cout<<endl;
    
        return 0;
    }

    地址:https://www.luogu.com.cn/problem/P1160

  • 相关阅读:
    集群架构搭建
    THUWC2019 游记
    【集训队互测2015】未来程序·改
    [NOIP2014普及组T1]珠心算测验
    [CF912D]Fishes
    [POJ2409]Let it Bead
    golang 统计系统测试覆盖率
    tcpdump常用方法
    数学闯关引发的思考
    linux lsof常用方法
  • 原文地址:https://www.cnblogs.com/forwhat00/p/13210259.html
Copyright © 2011-2022 走看看