1. 程式人生 > >「日常訓練」Brackets in Implications(Codeforces Round 306 Div.2 E)

「日常訓練」Brackets in Implications(Codeforces Round 306 Div.2 E)

ORC != make ace second brackets include tdi else

題意與分析

稍微復雜一些的思維題。反正這場全是思維題,就一道暴力水題(B)。

代碼

#include <bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)
#define per(i, a, b) for (repType i = (a); i >= (b); --i)
#define QUICKIO                      ios::sync_with_stdio(false);     cin.tie(0);                      cout.tie(0);
using namespace std;
using ll=long long;
using repType=int;

int main()
{
    int n; cin>>n; 
    vector<int> vec;
    rep(i,1,n)
    {
        int tmp; cin>>tmp; vec.PB(tmp);
    }
    if(n==1) 
    {
        if(vec[0]==0) {cout<<"YES"<<endl; cout<<0<<endl;}
        else cout<<"NO"<<endl;
    }
    else
    {
        if(vec[n-1]==1) cout<<"NO"<<endl;
        else if(vec[n-1]==0 && vec[n-2]==1)
        {
            cout<<"YES"<<endl;
            rep(i,0,n-1)
            {
                if(i!=0) cout<<"->";
                cout<<vec[i];
            }
            cout<<endl;
        }
        else // 0 0
        {
            rep(i,0,n-3)
            {
                if(vec[i]==0)
                {
                    cout<<"YES"<<endl;
                    rep(j,0,i-1)
                    {
                        if(j!=0) cout<<"->";
                        cout<<vec[j];
                    }
                    if(i-1>=0) cout<<"->";
                    cout<<"(0->(";
                    rep(j,i+1,n-3)
                    {
                        cout<<vec[j]<<"->";
                    }
                    cout<<"0))->0"<<endl;
                    return 0;
                }
            }
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

「日常訓練」Brackets in Implications(Codeforces Round 306 Div.2 E)