给出一个四个规则

0->0=1  0->1=1

1->0=0  1->1=0

我自己当时一味的去找规律,没有把式子好好推一推。

当然每个人都能想到a[n]=0是必须的

当a[n-1]=1的时候,直接输出即可,因为前面无论到0还是1,最后与n-1结合都是1,而这正式我们需要的

那么问题来了,a[n-1]=0时,我们该如何操作呢?

思考这样我们以及知道的条件,考虑某一段010101010000111....1,只要是以1为结尾的,按顺序计算都是1。

再思考如何有两个0,我们发现(0(111...0))这个式子是恒等于1的,无论中间1是多少个,而只要这等于1后,无论(0(111...0))的前面位置按顺序计算是什么,答案都是1,然后再和0计算,答案就是0

反思:自己思考的时候,一味的僵化,没有把式子进行本质扩展和分析。同时脑子很乱,对于这种思维题,是大忌

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#define LL long long
using namespace std;
int a[];
int main()
{
int n;
while(~scanf("%d",&n))
{ for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
if (n==)
{
if(a[]==)
{
printf("YES\n0\n");
}
else
{
printf("NO\n");
}
}
else if (n==)
{
if (a[]== && a[]==)
{
printf("YES\n1->0\n");
}
else
{
printf("NO\n");
}
}else if (a[n]==){
printf("NO\n");
}
else
{
if (a[n-]==)
{
printf("YES\n");
for (int i=; i<=n; i++)
{
if (i-)
{
printf("->");
}
printf("%d",a[i]);
}
printf("\n");
}
else
{
int pos=-;
if (a[n]==)
{
for (int i=n-; i>=; i--)
{
if (a[i]==)
{
pos=i;
break;
}
}
if (pos==-)
{
printf("NO\n");
continue;
}
printf("YES\n");
for (int i=; i<pos; i++)
{
printf("%d->",a[i]);
}
printf("(0->(");
for (int i=pos+; i<=n-; i++)
{
printf("%d->",a[i]);
}
printf("0))->0\n");
}
else
{
printf("NO\n");
}
}
} }
return ;
}

CodeForces 550E Brackets in Implications 推理的更多相关文章

  1. codeforces #550E Brackets in Implications 结构体

    标题效果:定义集合中{0,1}\{0,1\}上的运算符"→\rightarrow",定义例如以下: 0→0=10\rightarrow 0=1 0→1=10\rightarrow ...

  2. CodeForces 550E Brackets in Implications(构造)

    [题目链接]:click here~~ [题目大意]给定一个逻辑运算符号a->b:当前仅当a为1b为0值为0,其余为1,构造括号.改变运算优先级使得最后结果为0 [解题思路]: todo~~ / ...

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

    E. Brackets in Implications Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  4. 「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)

    题意与分析 稍微复杂一些的思维题.反正这场全是思维题,就一道暴力水题(B).题解直接去看官方的,很详尽. 代码 #include <bits/stdc++.h> #define MP ma ...

  5. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

  6. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  7. Codeforces Round #306 (Div. 2) D.E. 解题报告

    D题:Regular Bridge 乱搞. 构造 这题乱搞一下即可了.构造一个有桥并且每一个点的度数都为k的无向图. 方法非常多.也不好叙述.. 代码例如以下: #include <cstdio ...

  8. XJTU Summer Holiday Test 1(Brackets in Implications-构造)

    B - Brackets in Implications Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并

    题目链接:http://codeforces.com/contest/381/problem/E  E. Sereja and Brackets time limit per test 1 secon ...

随机推荐

  1. JSF中run项目时候Tomcat8启动不了的一种方法

    把另一个博客内容迁移到这 我的问题是Tomcat是可以启动的 但是run那个jsp的时候 七月 10, 2016 3:14:54 下午 org.apache.tomcat.util.digester. ...

  2. spring mvc 中 controller 路径配置

    下图中,由于红色部分(value="/")的存在,导致 host:port/项目/dimlist 无法被映射到dimList方法,解决办法是将其去掉. package cn.bgo ...

  3. django安装与使用

    django安装与使用 --更新中 安装 我这里采用pip安装 pip install django 创建django工程 创建好的工程,会在当前目录.下 django-admin startproj ...

  4. 修正Percona Monitoring Plugins for Zabbix的一处脚本Bug

    今天小试了一把Percona Monitoring Plugins for Zabbix模板,自己辛辛苦苦写的那一大堆Python脚本,貌似用这个模板全都覆盖到了.但是,我也发现最新的版本percon ...

  5. [Hive_11] Hive 的高级聚合函数

    0. 说明 Hive 的高级聚合函数 union all | grouping sets | cube | rollup pv //page view 页面访问量 uv //user view 访问人 ...

  6. 解决Go依赖包安装问题

    最近在学习Go编写后端服务,先放出谢大的书镇楼: https://github.com/astaxie/build-web-application-with-golang/blob/master/zh ...

  7. C#事件の.net下的EventArgs和EventHandler

    事件参数(EventArgs) .Net框架里边提供的一个委托EventHandler来Handle事件. 一样,搞一个场景(这个场景是书里的):买车.经销商(CarDealer)会上新车(NewCa ...

  8. go基础之数组和切片

    数组 数组的定义: 数组是具有固定长度并拥有零个或者多个相同数据类型元素的序列 定义一个数组的方法:var 变量名[len] type 例子:var a[5] int //3个整数的数组var a[5 ...

  9. 解决Zabbix网页端Get value error: cannot connect to [[192.168.238.139]:10050]: [113] No route to host问题

    在安装配置完zabbix_agentd以后,网页端出现  Get value error: cannot connect to [[192.168.238.139]:10050]: [113] No ...

  10. NOsql总结

    NOsql总结 1.存储: 任意格式的数据:值对存储,列存储,文档存储,图形数据库 灵活的表结构支持:类型动态.scheme动态: 灵活的存储形式:列存储: 弱关系:NoSQL数据库种类繁多,但是一个 ...