E. Brackets in Implications

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/550/problem/E

Description

Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.

Implication is written by using character '', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:

When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,

.

When there are brackets, we first calculate the expression in brackets. For example,

.

For the given logical expression determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.

Input

The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression.

The second line contains n numbers a1, a2, ..., an (), which means the values of arguments in the expression in the order they occur.

Output

Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0.

Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line.

The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a1, a2, ..., an.

The expression should be correct. More formally, a correct expression is determined as follows:

Expressions "0", "1" (without the quotes) are correct.
    If v1, v2 are correct, then v1->v2 is a correct expression.
    If v is a correct expression, then (v) is a correct expression.

The total number of characters in the resulting expression mustn't exceed 106.

If there are multiple possible answers, you are allowed to print any of them.

Sample Input

4
0 1 1 0

Sample Output

YES
(((0)->1)->(1->0))

HINT

题意

构造出一个等式,按着上面的规律,使得答案为0

题解:

最后一位肯定得为0

只有2个0也无解

然后只用管3个0的情况

然后构造出a1->a2->ak->(0->(b1->(b2->....->(bk->0))))->0

然后就完了 = =

只用管到最近的三个0

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** char num[]; int main(){
int n;
scanf(" %d",&n);
for(int i=;i<n;++i)
scanf(" %c",&num[i]);
if( n== ){
if( num[]=='' ) printf("YES\n0\n");
else printf("NO\n");
return ;
}
if( n== ){
if( num[]=='' && num[]=='' )
printf("YES\n1->0\n");
else printf("NO\n");
return ;
}
if( num[n-]=='' ){
printf("NO\n");
return ;
}
if( num[n-]=='' ){
printf("YES\n");
for(int i=;i<n-;++i)
printf("%c->",num[i]);
printf("%c",num[n-]);
printf("\n");
return ;
}
int cnt = , from = - , to = n-;
for(int i=n-;i>= && from==-;--i)
if( num[i]=='' )
from = i;
if( from==- ){
printf("NO\n");
return ;
}
printf("YES\n");
for(int i=;i<from;++i)
printf("%c->",num[i]);
for(int i=from;i<to;++i)
printf("(%c->",num[i]);
printf("%c",num[to]);
for(int i=from;i<to;++i)
printf(")");
printf("->%c\n",num[n-]);
}

最新文章

  1. 第一个WCF的程序
  2. 【quartz】 入门
  3. 信号之sigpending函数
  4. mysql查询随机几条数据(速度快)
  5. Thinkphp 事物问题
  6. 通过并行 提高批量审核PDF性能
  7. BZOJ 1005: [HNOI2008]明明的烦恼( 组合数学 + 高精度 )
  8. hdu 1063 Exponentiation 大数
  9. 在LaTeX 与 LyX 中设置“Contents”为“目录”
  10. 写java代码遇到的一些问题
  11. 深度理解DOM拷贝clone()
  12. js 从一个对象中找到属性值相等的集合
  13. python 阿狸的进阶之路(4)
  14. linux挂载ntfs格式的硬盘
  15. [Go] 正则表达式 示例
  16. 微信小程序开发-滑动操作
  17. [USACO19FEB]Moorio Kart
  18. Git---远程仓库之从远程仓库克隆03
  19. Python all() 函数
  20. EF 联合查询

热门文章

  1. Golang 做的几个跟性能有关的工具
  2. 第二个UI脚本--Python+selenium之unittest+HTMLtestRunner及python的继承
  3. python在linux上的GUI无法弹出界面
  4. Inverse是hibernate双向关系中的基本概念。inverse的真正作用就是指定由哪一方来维护之间的关联关系。当一方中指定了“inverse=false”(默认),那么那一方就有责任负责之间的关联关系,说白了就是hibernate如何生成Sql来维护关联的记录
  5. 程序语言的奥妙:算法解读 &mdash;&mdash;读书笔记
  6. c语言的几个重要知识点
  7. 理解display:inline、block、inline-block
  8. Determining IP information for eth0... failed; no link present. Check cable?
  9. cocos2dx移植android平台-我的血泪史
  10. Javascript函数柯里化(curry)