标签:bool logs log printf include blog span scan pac
洛谷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 }
标签:bool logs log printf include blog span scan pac
原文地址:http://www.cnblogs.com/third2333/p/6914720.html