现在的位置: 首页 > 综合 > 正文

poj 1068 Parencodings

2018年04月23日 ⁄ 综合 ⁄ 共 1360字 ⁄ 字号 评论关闭

水题,有关括号匹配? 纯模拟,可以肆无忌惮的写循环的感觉真是爽!

不过我写模拟的代码总是那么丑,自己都不好意思看尴尬

code

#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define lson l,m,rt << 1
#define rson m + 1,r,rt<<1|1
#define SD(a) scanf("%d",&(a))
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define readf freopen("input.txt","r",stdin)
#define writef freopen("output.txt","w",stdout)
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
const int maxn = 51;
const int INF = ~0U>>1;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const double pi = acos(-1.0);
using namespace std;
short S[maxn];
bool vis[maxn];
int main()
{
    int cas;
    SD(cas);
    while(cas--){
        SET(S,0);
        SET(vis,false);
        int N;
        SD(N);
        FOR(i,1,N){
            int t;
            SD(t);
            int cnt=0;
            FOR(j,1,50){
                if(cnt==t){
                    FOR(k,j,50){
                        if(!S[k]){
                            S[k]=2;break;
                        }
                    }
                    break;
                }
                if(!S[j]){
                    S[j]=1;cnt++;
                }else if(S[j]==1) cnt++;
            }
        }
        bool flag=false;
        for(int i=1;S[i];i++){
            if(S[i]==2){
                int cnt=0;
                FOD(j,i,1){
                    if(S[j]==1 && !vis[j]){
                        vis[j]=true;
                        cnt++;
                        break;
                    }
                    if(vis[j]==true && S[j]==1) cnt++;
                }
                if(flag) PS;
                PD(cnt);
                flag=true;
            }
        }
        LN;
    }
    return 0;
}

抱歉!评论已关闭.