当前位置: 首页 > news >正文

Codeforces Round #306 (Div. 2) E. Brackets in Implications 构造

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[20];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************

char num[100004];

int main(){
    int n;
    scanf(" %d",&n);
    for(int i=0;i<n;++i)
        scanf(" %c",&num[i]);
    if( n==1 ){
        if( num[0]=='0' ) printf("YES\n0\n");
        else printf("NO\n");
        return 0;
    }
    if( n==2 ){
        if( num[0]=='1' && num[1]=='0' )
            printf("YES\n1->0\n");
        else printf("NO\n");
        return 0;
    }
    if( num[n-1]=='1' ){
        printf("NO\n");
        return 0;
    }
    if( num[n-2]=='1' ){
        printf("YES\n");
        for(int i=0;i<n-1;++i)
            printf("%c->",num[i]);
        printf("%c",num[n-1]);
        printf("\n");
        return 0;
    }
    int cnt = 0 , from = -1 , to = n-2;
    for(int i=n-3;i>=0 && from==-1;--i)
        if( num[i]=='0' )
            from = i;
    if( from==-1 ){
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    for(int i=0;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]);
}

 

相关文章:

  • ZH奶酪:【数据结构与算法】并查集基础
  • lnmp 在nginx中配置相应的错误页面error_page
  • Android 官方命令深入分析之Android Debug Bridge(adb)
  • 使用cardme读写VCard文件,实现批量导入导出电话簿
  • 使用SQL Server 2008远程链接时SQL数据库不成功的解决方法
  • 做基准测试时tpcc相关注意点
  • 分享一个 ftp下载、解压、更新依赖库文件的 python 脚本
  • wifi的web 认证。
  • Servlet开篇
  • Linode Centos6.5从零开始装环境...流水账
  • 在Linux系统中如何识别U盘
  • sql语句中in与exist not in与not exist 的区别
  • android 关于 android sdk manager 更新,下载慢的问题
  • (笔试题)合法字符串
  • 【重磅】大众点评运维架构图文详解 @马哥教育联合创始人张冠宇
  • 2017-09-12 前端日报
  • angular2开源库收集
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • ES6之路之模块详解
  • httpie使用详解
  • IP路由与转发
  • JavaScript-Array类型
  • JDK 6和JDK 7中的substring()方法
  • Swift 中的尾递归和蹦床
  • 前端性能优化--懒加载和预加载
  • 让你的分享飞起来——极光推出社会化分享组件
  • 无服务器化是企业 IT 架构的未来吗?
  • 用jquery写贪吃蛇
  • 哈罗单车融资几十亿元,蚂蚁金服与春华资本加持 ...
  • 交换综合实验一
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码
  • # 睡眠3秒_床上这样睡觉的人,睡眠质量多半不好
  • #[Composer学习笔记]Part1:安装composer并通过composer创建一个项目
  • (16)Reactor的测试——响应式Spring的道法术器
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (五)大数据实战——使用模板虚拟机实现hadoop集群虚拟机克隆及网络相关配置
  • (学习日记)2024.01.09
  • .gitattributes 文件
  • .gitignore文件_Git:.gitignore
  • .libPaths()设置包加载目录
  • .NET 3.0 Framework已经被添加到WindowUpdate
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .NET Standard 的管理策略
  • .net 简单实现MD5
  • .NET/C# 避免调试器不小心提前计算本应延迟计算的值
  • [Android] Upload package to device fails #2720
  • [AndroidStudio]_[初级]_[修改虚拟设备镜像文件的存放位置]
  • [Codeforces] number theory (R1600) Part.11
  • [excel与dict] python 读取excel内容并放入字典、将字典内容写入 excel文件
  • [Go WebSocket] 多房间的聊天室(五)用多个小锁代替大锁,提高效率
  • [go 反射] 进阶
  • [HNOI2010]BUS 公交线路
  • [HTML API]HTMLCollection
  • [IE编程] 如何设置IE8的WebBrowser控件(MSHTML) 的渲染模式
  • [Leetcode] 寻找数组的中心索引