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

    洛谷P1160 队列安排   链表 

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <cstdlib>
     5 #include <string>
     6 #include <algorithm>
     7 #include <iomanip>
     8 #include <iostream> 
     9 using namespace std ; 
    10 
    11 struct node{
    12     int l,r ; 
    13 };
    14 node a[100011] ;
    15 int n,m,x,type,k ;
    16 bool f[100011] ;
    17 
    18 int main()
    19 {
    20     scanf("%d",&n) ;
    21     f[ 1 ] = 1 ;
    22     for(int i=2;i<=n;i++) 
    23     {
    24         f[ i ] = 1 ;
    25         scanf("%d%d",&x,&type) ; 
    26         a[ 0 ].l = 0 ;
    27         a[ 0 ].r = 0 ;
    28         if(type==0) 
    29         {
    30             a[ i ].r = x ;
    31             a[ i ].l = a[ x ]. l ; 
    32             a[ a[ i ].l ].r = i ;
    33             a[ a[ i ].r ].l = i ;
    34         }
    35         else 
    36         {
    37             a[ i ].l = x ;
    38             a[ i ].r = a[ x ].r ;
    39             a[ a[ i ].l ].r = i ;
    40             a[ a[ i ].r ].l = i ;
    41         }
    42         
    43     }
    44     scanf("%d",&m) ;
    45     for(int i=1;i<=m;i++) 
    46     {
    47         scanf("%d",&x) ;
    48         if(!f[ x ]) continue ; 
    49         f[ x ] = 0 ;
    50         a[ a[ x ].l ].r = a[ x ].r ;
    51         a[ a[ x ].r ].l = a[ x ].l ;
    52         a[ x ].l = 0 ;
    53         a[ x ].r = 0 ; 
    54     }
    55     for(int i=1;i<=n;i++) 
    56         if(f[ i ]&&!a[i].l) 
    57         {
    58             k = i ;
    59             break ;
    60         }
    61     printf("%d ",k) ;
    62     while( a[ k ].r ) 
    63         printf("%d ",a[ k ].r),k = a[ k ].r ; 
    64     return 0 ;
    65 }
  • 相关阅读:
    【HDU3681】Prison Break-状态压缩DP+BFS+二分答案
    【BashuOJ3520】警察局长-最短路树+树上背包+概率DP
    【POJ1201】Intervals-差分约束系统+单源最长路
    【BashuOJ2041】最大矩形-矩阵型DP
    【BashuOJ2041】最大矩形-矩阵型DP
    deleted
    deleted
    deleted
    deleted
    deleted
  • 原文地址:https://www.cnblogs.com/third2333/p/6914720.html
Copyright © 2011-2022 走看看