「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)
Posted samhx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)相关的知识,希望对你有一定的参考价值。
题意与分析
稍微复杂一些的思维题。反正这场全是思维题,就一道暴力水题(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)的主要内容,如果未能解决你的问题,请参考以下文章