zoukankan      html  css  js  c++  java
  • HDU 3328 Flipper

    题解:直接建n个栈,模拟过程即可……

    #include <cstdio> 
    #include <cstring> 
    #include <stack> 
    using namespace std;  
    int main(){  
        int n,n2,a,ar[105],cas=1;  
        bool rs[105];
        char str[105];  
        while(scanf("%d",&n),n){  
            scanf("%s",str);  
            for(int i=0;i<n;i++)rs[i]=(str[i]=='U')?1:0;
            int l=0,r=n-1;  
            stack st[105];  
            for(int i=0;i<n;i++)st[i].push(i); 
            scanf("%s",str);
            for(int i=0;i<n-1;i++){  
                if(str[i]=='L'){  
                    l++;  
                    for(int j=0;j<l;j++)rs[j]=!rs[j];
                    while(!st[l-1].empty()){
                        st[l].push(st[l-1].top());  
                        st[l-1].pop();  
                    }  
                }else{  
                    r--;  
                    for(int j=n-1;j>r;j--)rs[j]=!rs[j];
                    while(!st[r+1].empty()){  
                        st[r].push(st[r+1].top());  
                        st[r+1].pop();  
                    }  
                }  
            }
            for(int i=0;i<n;i++){ar[i]=st[l].top();st[l].pop();}
            printf("Pile %d
    ",cas++);  
            scanf("%d",&n2);  
            while(n2--){  
                scanf("%d",&a);  
                printf("Card %d is a face ",a);  
                a--;  
                printf(rs[ar[a]]?"up ":"down ");  
                printf("%d.
    ",ar[a]+1);  
            }  
        }  
        return 0;  
    }  
    
  • 相关阅读:
    matrix_last_acm_4
    matrix_last_acm_3
    matrix_last_acm_2
    matrix_last_acm_1
    2015亚洲区北京站网络赛
    poj 1062 昂贵的聘礼 最短路
    2-SAT !!
    hdu 4925
    hdu 4927 Java大数
    poj3687 拓扑排序 还没怎么搞明白 回头再想想
  • 原文地址:https://www.cnblogs.com/forever97/p/3668848.html
Copyright © 2011-2022 走看看