题目链接】:click here~~

题目大意】给定一个逻辑运算符号a->b:当前仅当a为1b为0值为0,其余为1,构造括号。改变运算优先级使得最后结果为0

解题思路】:

todo~~

/*

思路:

1.假设最后一位是1,不管怎样结果不会为0.puts("NO");

2.那么有解的情况下最后一位必为0

  2.1.进一步发现,事实上倒数第二位必为1,仅仅有1前面的结果和该位1结合才干等于1,进一步1->0=0;

  2.2.假设1前面是0。那么合并这两位数,组成1,递推2.1

*/

代码:

#include <bits/stdc++.h>
using namespace std; const int N=1e5+10;
typedef long long LL;
typedef unsigned long long LLU;
int num[N];
int n,m,l,r,ans,cnt,top;
int zero,one;
int main()
{
while(cin>>n)
{
zero=one=0;
for(int i=0; i<n; ++i)
{
scanf("%d",&num[i]);
if(num[i]==0) ++zero;
else ++one;
}
int a3=num[n-1];
int a2=num[n-2];
int a1=num[n-3];
if(a3==0&&(a2==1||zero!=2))//保证最后一位是0,倒数第二位是1
{
puts("YES");
printf("(");
for(int i=0; i<=n-3; ++i)
{
printf("(%d->",num[i]);
}
printf("%d",a2);
for(int i=0; i<=n-3; ++i)
printf(")");
if(n-1) printf("->0");
printf(")");
puts("");
}
else puts("NO");
}
return 0;
}

最新文章

  1. 通过 UDP 发送数据的简单范例
  2. C#线程同步的几种方法
  3. [转]com.devicepush.cordova-phonegap Device Push Notification Plugin
  4. 入门:HTML:hello world!
  5. Codevs1299 切水果
  6. jstl数字转日期
  7. Linux多线程之同步
  8. IOS UIButton 自定义的补充学习
  9. SkinSharp用法
  10. [改善Java代码]避免对象的浅拷贝
  11. DDL_数据库模式定义语言
  12. 重现PHP Core的调用栈
  13. void指针、NULL指针和未初始化指针
  14. EasyUI 1.3之前DataGrid中动态选中、获取Checkbox
  15. Fedora20-Xfce音频视频解码器及解决无声音问题[已解决]
  16. Windows下载地址
  17. 笔记整理--Linux守护进程
  18. javascript的页面加载及性能优化(兼容IE7)
  19. 关于Android 8.0java.lang.SecurityException: Permission Denial错误的解决方法
  20. Java高级面试题解析(一)

热门文章

  1. SpringCloud学习笔记(20)----Spring Cloud Netflix之服务网关Zuul的各种姿势
  2. nginx 子进程 woker process 启动失败的问题
  3. QT+OpenCV进行图像采集最小时延能够达到20ms
  4. 路飞学城Python-Day11
  5. [arc082e]ConvexScore
  6. EasyUI Combotree只选择叶子节点
  7. 特斯拉正加快部署第三代Autopilot自动驾驶计算机
  8. caioj 1152 快速求模 (快速幂)
  9. Linux系统信息查看命令大全[转]
  10. hdoj Let the Balloon Rise