CodeForces 550E Brackets in Implications(构造)
2024-08-31 13:56:26
【题目链接】: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;
}
最新文章
- 通过 UDP 发送数据的简单范例
- C#线程同步的几种方法
- [转]com.devicepush.cordova-phonegap Device Push Notification Plugin
- 入门:HTML:hello world!
- Codevs1299 切水果
- jstl数字转日期
- Linux多线程之同步
- IOS UIButton 自定义的补充学习
- SkinSharp用法
- [改善Java代码]避免对象的浅拷贝
- DDL_数据库模式定义语言
- 重现PHP Core的调用栈
- void指针、NULL指针和未初始化指针
- EasyUI 1.3之前DataGrid中动态选中、获取Checkbox
- Fedora20-Xfce音频视频解码器及解决无声音问题[已解决]
- Windows下载地址
- 笔记整理--Linux守护进程
- javascript的页面加载及性能优化(兼容IE7)
- 关于Android 8.0java.lang.SecurityException: Permission Denial错误的解决方法
- Java高级面试题解析(一)
热门文章
- SpringCloud学习笔记(20)----Spring Cloud Netflix之服务网关Zuul的各种姿势
- nginx 子进程 woker process 启动失败的问题
- QT+OpenCV进行图像采集最小时延能够达到20ms
- 路飞学城Python-Day11
- [arc082e]ConvexScore
- EasyUI Combotree只选择叶子节点
- 特斯拉正加快部署第三代Autopilot自动驾驶计算机
- caioj 1152 快速求模 (快速幂)
- Linux系统信息查看命令大全[转]
- hdoj Let the Balloon Rise